public static void Run()
        {
            int             x    = 3;
            IFoo            ifoo = new DelegateBenchmark();
            Func <int, int> del  = ifoo.Foo;

            //Func<int, int> del = (value) => value * 3;
            // Make sure everything's JITted:
            ifoo.Foo(3);
            del(3);

            Stopwatch sw = Stopwatch.StartNew();

            for (int i = 0; i < Iterations; i++)
            {
                x = ifoo.Foo(x);
            }
            sw.Stop();
            Console.WriteLine("Interface: {0}", sw.ElapsedMilliseconds);

            x  = 3;
            sw = Stopwatch.StartNew();
            for (int i = 0; i < Iterations; i++)
            {
                x = del(x);
            }
            sw.Stop();
            Console.WriteLine("Delegate: {0}", sw.ElapsedMilliseconds);
        }
        public static void Run()
        {
            int x = 3;
            IFoo ifoo = new DelegateBenchmark();
            Func<int, int> del = ifoo.Foo;
            //Func<int, int> del = (value) => value * 3;
            // Make sure everything's JITted:
            ifoo.Foo(3);
            del(3);

            Stopwatch sw = Stopwatch.StartNew();
            for (int i = 0; i < Iterations; i++)
            {
                x = ifoo.Foo(x);
            }
            sw.Stop();
            Console.WriteLine("Interface: {0}", sw.ElapsedMilliseconds);

            x = 3;
            sw = Stopwatch.StartNew();
            for (int i = 0; i < Iterations; i++)
            {
                x = del(x);
            }
            sw.Stop();
            Console.WriteLine("Delegate: {0}", sw.ElapsedMilliseconds);
        }
Exemple #3
0
 static void Main(string[] args)
 {
     //Thresholding2d.Run();
     DelegateBenchmark.Run();
 }