public static MyVector Add(MyVector v0, float v) { var rtn = new MyVector(v0.arr.Length); for (var i = 0; i < v0.arr.Length; i++) { rtn.arr[i] = v0.arr[i] + v; } return(rtn); }
public static float Dot(MyVector v0, MyVector v1) { float rtn = 0; for (var i = 0; i < v0.arr.Length; i++) { rtn += v0.arr[i] * v1.arr[i]; } return(rtn); }
public static MyVector Div(MyVector v0, MyVector v1) { var rtn = new MyVector(v0.arr.Length); for (var i = 0; i < v0.arr.Length; i++) { rtn.arr[i] = v0.arr[i] / v1.arr[i]; } return(rtn); }
private static void Main(string[] args) { var size = 100000; //100000 var loop = 10000; var arr = new float[size]; for (var i = 0; i < arr.Length; i++) { arr[i] = i; } var arr1 = new float[size]; for (var i = 0; i < arr.Length; i++) { arr1[i] = i * 2; } var s0 = new VectorSimd(arr); var s1 = new VectorSimd(arr1); var v0 = new MyVector(arr); var v1 = new MyVector(arr1); var sw = new Stopwatch(); sw.Start(); for (var i = 0; i < loop; i++) { var tmp = VectorSimd.Dot(s0, s1); } sw.Stop(); var a = sw.ElapsedMilliseconds; Console.WriteLine("vs=" + a); sw.Reset(); sw.Start(); for (var i = 0; i < loop; i++) { var tmp = MyVector.Dot(v0, v1); } sw.Stop(); var b = sw.ElapsedMilliseconds; Console.WriteLine("mv=" + b); Console.WriteLine(1.0 * b / a); }