Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }