public void BenchmarkCtorActivator() { var watch = new Stopwatch(); watch.Reset(); watch.Start(); for (int i = 0; i < count; i++) { testReference = Activator.CreateInstance <TestClass>(); } watch.Stop(); BenchmarkResult.Add("Ctors", "Activator", watch.Elapsed); }
public void BenchmarkCtorExact() { var watch = new Stopwatch(); watch.Reset(); watch.Start(); for (int i = 0; i < count; i++) { testReference = new TestClass(); } watch.Stop(); BenchmarkResult.Add("Ctors", "Exact", watch.Elapsed); }
public void BenchmarkCtorReflection() { var ctor = typeof(TestClass).GetConstructor(Type.EmptyTypes); var watch = new Stopwatch(); watch.Reset(); watch.Start(); for (int i = 0; i < count; i++) { testReference = (TestClass)ctor.Invoke(null); } watch.Stop(); BenchmarkResult.Add("Ctors", "Reflection", watch.Elapsed); }
public void BenchmarkCtorEmit() { var ctor = new EmitConstructor(typeof(TestClass)); var watch = new Stopwatch(); watch.Reset(); watch.Start(); for (int i = 0; i < count; i++) { testReference = (TestClass)ctor.Create(); } watch.Stop(); BenchmarkResult.Add("Ctors", "Emit", watch.Elapsed); }
public void BenchmarkBoxing(string category, string name, IInvoker invoker) { Stopwatch watch = new Stopwatch(); watch.Reset(); watch.Start(); for (int i = 0; i < count; i++) { var width = invoker.GetValue(testReference); width = 0; invoker.SetValue(testReference, width); } watch.Stop(); BenchmarkResult.Add($"{category}(Boxing)", name, watch.Elapsed); }
public void Benchmark <T, V>(string category, string name, IInvoker <T, V> invoker) { Stopwatch watch = new Stopwatch(); watch.Reset(); watch.Start(); for (int i = 0; i < count; i++) { var width = invoker.GetValue(testReference); width = default(V); invoker.SetValue(testReference, width); } watch.Stop(); BenchmarkResult.Add(category, name, watch.Elapsed); }
public void ShortToIntStruct() { Stopwatch watch = new Stopwatch(); watch.Reset(); watch.Start(); for (short i = 0; i < 100; i++) { for (short j = 0; j < 100; j++) { var value = Helper.TwoToOneStruct(i, j); Helper.OneToTwoStruct(value, out var a, out var b); Assert.AreEqual(i, a); Assert.AreEqual(j, b); } } watch.Stop(); BenchmarkResult.Add($"ShortToInt", nameof(ShortToIntStruct), watch.Elapsed); }
public void IntToLongPointer() { Stopwatch watch = new Stopwatch(); watch.Reset(); watch.Start(); for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { var value = Helper.TwoToOnePointer(i, j); Helper.OneToTwoPointer(value, out var a, out var b); Assert.AreEqual(i, a); Assert.AreEqual(j, b); } } watch.Stop(); BenchmarkResult.Add($"IntToLong", nameof(IntToLongPointer), watch.Elapsed); }