SIMD C# - 测试显示速度没有差异。为什么?

时间:2014-05-17 17:33:18

标签: c# simd ryujit

供参考,请参阅:http://code.msdn.microsoft.com/windowsdesktop/SIMD-Sample-f2c8c35a

这不是真实的测试。我已经安装了Ryu-JIT,并在运行" enable-JIT.cmd"之后运行了以下代码。并且在运行" disable-JIT.cmd"之后。我已关闭"在模块加载时抑制JIT优化"。

这些都没有显示出循环速度的任何差异,或者它们是否会运行。目前,他们都达到了1.1秒。

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 个答案:

没有答案