void Benchmark_MemCopy() { int[] memItems = { 32, 64, 128, 256, Env.CHUNK_SIZE_WITH_PADDING_POW_2, Env.CHUNK_SIZE_POW_3 }; int[] iters = { 1000000, 1000000, 50000, 50000, 10000, 5000 }; Debug.Assert(memItems.Length == iters.Length); int maxItems = memItems[memItems.Length - 1]; byte[] bd1 = Helpers.CreateArray1D <byte>(maxItems * StructSerialization.TSSize <BlockData> .ValueSize); for (int i = 0; i < bd1.Length; i++) { bd1[i] = 1; } bd2 = Helpers.CreateArray1D <BlockData>(maxItems); for (int i = 0; i < bd2.Length; i++) { bd2[i] = new BlockData(0x101); } BlockData dummy = new BlockData(0x101); TestClass1 tc1 = new TestClass1(); TestClass2 tc2 = new TestClass2(); Debug.Log("Bechmark - memory copy"); using (StreamWriter writer = File.CreateText("perf_memcpy.txt")) { for (int i = 0; i < iters.Length; i++) { int loops = iters[i]; int items = memItems[i]; uint bytes = (uint)items * (uint)StructSerialization.TSSize <BlockData> .ValueSize; Debug.LogFormat("Bytes to copy: {0}", bytes); writer.WriteLine("Bytes to copy: {0}", bytes); { float[] number = { 0 }; t = Clock.BenchmarkTime( () => { tc1.Copy(bd1, 0, 0, bytes); }, loops); t2 = t / loops; output = string.Format("MemoryCopy\nout:{0}\ntime:{1} | {2} ms", number[0], t.ToString(CultureInfo.InvariantCulture), t2.ToString(CultureInfo.InvariantCulture)); Debug.Log(output); foreach (string s in output.Split('\n')) { writer.WriteLine(s); } } for (int j = 0; j < items; j++) { Assert.IsTrue(tc1[j] == dummy); } { float[] number = { 0 }; double t = Clock.BenchmarkTime( () => { tc2.Copy(bd2, 0, 0, items); }, loops); t2 = t / loops; output = string.Format("ArrayCopy\nout:{0}\ntime:{1} | {2} ms", number[0], t.ToString(CultureInfo.InvariantCulture), t2.ToString(CultureInfo.InvariantCulture)); Debug.Log(output); foreach (string s in output.Split('\n')) { writer.WriteLine(s); } } for (int j = 0; j < items; j++) { Assert.IsTrue(tc2[j] == dummy); } } } }