I wrote code for testing, which is faster. I am running the code in Release x64. I have VS 2015 Pro with .NET Framework 4.6.
#if SYSTEMMATHLIB using System.Numerics; #else using Engine.Mathematic; #endif namespace Engine.Editor { public static class Program { public static void Main() { #if SYSTEMMATHLIB Console.WriteLine("Hardware Acceleration: " + Vector.IsHardwareAccelerated.ToString()); #endif Stopwatch sw = new Stopwatch(); sw.Start(); #if SYSTEMMATHLIB for (int i = 0; i < 1000000; i++) { Matrix4x4 m = Matrix4x4.CreateRotationZ(0.50f); m.Translation = new Vector3(5, 10, 15); Matrix4x4 m2 = Matrix4x4.CreateRotationX(0.50f); m2.Translation = new Vector3(-5, 10, -15); Matrix4x4 m3 = m * m2; Matrix4x4 inv; Matrix4x4.Invert(m3, out inv); } #else for (int i = 0; i < 1000000; i++) { Matrix m = Matrix.RotationZ(0.50f); m.TranslationVector = new Vector3(5, 10, 15); Matrix m2 = Matrix.RotationX(0.50f); m2.TranslationVector = new Vector3(-5, 10, -15); Matrix m3 = m * m2; Matrix inv; Matrix.Invert(ref m3, out inv); } #endif long mili = sw.ElapsedMilliseconds; sw.Stop(); Console.WriteLine("Total mili: " + mili.ToString()); Console.ReadLine(); } } }
Well, if I ran it using System.Numerics from Framework 4.6 (Nuget version), it takes 212 ms to calculate. If I switch it to my library, which is just C # code to compute it, it also takes about 210 ms. It's a bit strange? I though SIMD should be faster!
By the way, IsHardwareAccelerated returns "True".
So what am I doing wrong?
For reference only: C ++ without SIMD works for 390ms and 77ms with SIMD.
source share