sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.7k stars 638 forks source link

Performance Analysis - Sharpdx Mathematics vs System.Numerics.Vectors #904

Closed h1cks closed 7 years ago

h1cks commented 7 years ago

@xoofx - Just FYI.

I've done some review of the performance between the SIMD based Vector library vs Sharpdx Vector.

I tested not only the libraries but also the platform, Namely .NET Core UWP application vs a Windows Forms Application.

Before suggesting/querying if Sharpdx should be a candidate move. I did some testing. This is basically FYI, but my tests were against the Numerics Matrix4x4 vs Sharpdx Matrix and the Numerics Vector3 class vs Sharpdx Vector3.

Testing was Vector3 multiply and divide and Matrix Transform to test multiply of a vector3. The only test I haven't performed is the Matrix * Matrix. But after testing these, I dont feel further testing is really warranted at the moment.

All libraries used for .NET libraries were release candidates. Sharpdx was 3.1.1. Approach was a simple form with the same code base used for testing. Any GUI component performance impacts were excluded from the test.

Results:

100 million Vector3 Multiplies and 100 million divides

.NET Core Application - Release - (Mult/Divide - System Numerics) - 1012ms/880ms Windows Form Application - Release - (Mult/Divide - System Numerics) - 319ms/834ms

.NET Core Application - Release - (Mult/Divide - Sharpdx) - 132ms/564ms Windows Form Application - Release - (Mult/Divide - Sharpdx) - 692ms/832ms

10 Million Matrix Transforms

.NET Core Application - Release - (Transform - System Numerics) - 63ms .NET Core Application - Release - (Transform - Sharpdx) - 44ms

Windows Form Application - Release - (Transform - System Numerics) - 101ms Windows Form Application - Release - (Transform - Sharpdx) - 148ms

In all cases, DEbug mode was roughly upwards of 50% to 100% slower as expected.

But my conclusion is, SIMD library doesn't seem to be an option for Vector3. I do know there was some interest originally from @xoofx when this was initially released. But commend the SharpDX libraries being quicker in .NET Core UWP applications, and is impressive. Obviously Numerics Vectors is faster in Windows Forms (than .NET Core), it currently is being beaten badly by Sharpdx in .NET Core but not Windows forms.

Edit - clarified conclusion more.

Axiverse commented 7 years ago

Under Vec3 mult, do you have .NET Core Application backwards? SharpDX is stated to be much faster.

h1cks commented 7 years ago

Hi, no, I tested this multiple times. I have been doing some reading and there seems to be some issues with .NET Core and the current SIMD components within System.Numerics.Vectors. Yes, I was confused too, but I have done a brute force test on both and number are as is (within +- 5ms).

Yes, it is weird, and I would be happy for someone to revalidate these numbers themselves! :)

h1cks commented 7 years ago

I've just ran a test where I have forced it to x64 rather than x86. Substantially different. Retested x86 and as per original results, basically same.

X64 Compiled - Windows Form

Windows Form Application - Release - (Mult/Divide - System Numerics) - 158ms/349ms Windows Form Application - Release - (Mult/Divide - Sharpdx) - 163ms/554ms Windows Form Application - Release - (Transform - System Numerics) -88ms Windows Form Application - Release - (Transform - Sharpdx) - 143ms

64 bit is very friendly to System Numerics, the bottleneck is gone. Performance is negligible improvement on Numerics for transform, Sharpdx seems to suffer a little under x64 for mult.

x64 - .NET Core

.NET Core Application - Release - (Mult/Divide - System Numerics) - 694ms/5556ms .NET Core Application - Release - (Mult/Divide - Sharpdx) - 131ms/567ms .NET Core Application - Release - (Transform - System Numerics) - 63ms .NET Core Application - Release - (Transform - Sharpdx) - 44ms

The 5556ms IS NOT a mistake, its horrible. Retested 4 times, and confirms much of what I have read about the SIMD instructions being problematic in compilation in .NET Core.

QuantumDeveloper commented 7 years ago

Did you enable option "optimize code"? because simd will work only if this option is enabled.

h1cks commented 7 years ago

Yes, I did in all cases

xoofx commented 7 years ago

Thanks for the benchmark. A bit surprised by the results that System.Numerics is not faster. You should push a simple gist/or github project and use BenchmarkDotnet so we can really make sure that the test doesn't have any flaws.

h1cks commented 7 years ago

At the moment i don't have much time to do a more in depth test. This is just fyi.