SIMD C# - Test shows no difference in speed. Why?

790 Views Asked by At

For reference, see: http://code.msdn.microsoft.com/windowsdesktop/SIMD-Sample-f2c8c35a

This is not a real-world test. I've installed Ryu-JIT, and ran the following code after running "enable-JIT.cmd" and after running "disable-JIT.cmd". I've turned off "Suppress JIT optimization on module load".

None of those show any difference in the speed of the loops, or whether they will run. Currently, they both hit 1.1~ seconds.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;


namespace SimdTest
{
    class Program
    {
        static void Main(string[] args)
        {
            MyVector3 am = new MyVector3(1, 2, 4);
            MyVector3 bm = new MyVector3(4, 2, 1);

            Vector3f at = new Vector3f(1, 2, 4);
            Vector3f bt = new Vector3f(4, 2, 1);


            int count = 200000000;


            TestMine(ref am, ref bm, count);
            TestTheirs(ref at, ref bt, count);
            Console.ReadKey(true);
        }

        private static void TestMine(ref MyVector3 am, ref MyVector3 bm, int count)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();
            for (int i = 0; i < count; ++i)
                am += bm;
            watch.Stop();
            Console.WriteLine(watch.Elapsed.TotalSeconds);
        }

        private static void TestTheirs(ref Vector3f at, ref Vector3f bt, int count)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();
            for (int i = 0; i < count; ++i)
                at += bt;
            watch.Stop();
            Console.WriteLine(watch.Elapsed.TotalSeconds);
        }
    }


    struct MyVector3
    {
        public float x { get { return _x; } }
        public float y { get { return _y; } }
        public float z { get { return _z; } }


        private float _x;
        private float _y;
        private float _z;


        public MyVector3(float x, float y, float z)
        {
            this._x = x;
            this._y = y;
            this._z = z;
        }


        public static MyVector3 operator +(MyVector3 lhs, MyVector3 rhs)
        {
            return new MyVector3(lhs._x + rhs._x, lhs._y + rhs._y, lhs._z + rhs._z);
        }
    }
}
0

There are 0 best solutions below