public void EqualsTest() { var loopCount = 1000; var state1 = SampleState.Create(loopCount); var state2 = SampleState.Create(loopCount); var watch = new Stopwatch(); var timeOfEquality = 0; var timeOfCustomEquals = 0; { watch.Reset(); watch.Start(); Assert.IsTrue(state1.Equals(state2)); watch.Stop(); timeOfEquality = watch.Elapsed.Milliseconds; } { watch.Reset(); watch.Start(); Assert.IsTrue(state1.CustomEquals(state2)); watch.Stop(); timeOfCustomEquals = watch.Elapsed.Milliseconds; } var gain = 100 * (double)timeOfCustomEquals / timeOfEquality; UnityEngine.Debug.Log(string.Format( "[Perf] loops: {0}, CustomEquals: {1}[ms], AutoEquals: {2}[ms], gain {3}%", loopCount, timeOfCustomEquals, timeOfEquality, gain.ToString("F2") )); }
public void CloneTest() { var loopCount = 100; var state = SampleState.Create(loopCount); var watch = new Stopwatch(); var timeOfCustomClone = 0; var timeOfAutoClone = 0; var timeOfReflectionClone = 0; { watch.Reset(); watch.Start(); state.CustomClone(); watch.Stop(); timeOfCustomClone = watch.Elapsed.Milliseconds; } { watch.Reset(); watch.Start(); state.Clone(); watch.Stop(); timeOfAutoClone = watch.Elapsed.Milliseconds; } { watch.Reset(); watch.Start(); state.ReflectionClone(); watch.Stop(); timeOfReflectionClone = watch.Elapsed.Milliseconds; } // dummy check Assert.IsTrue(true); { UnityEngine.Debug.Log(string.Format( "[Perf] loop: {0}, CustomClone: {1}[ms], ReflectionClone: {2}[ms], AutClone: {3}[ms]", loopCount, timeOfCustomClone, timeOfReflectionClone, timeOfAutoClone )); } }