public static void Run()
        {
            Console.WriteLine("2)");

            DateTime      start = DateTime.Now;
            DynamicMethod dm    = Util.Compile("X = abs((5 - Y) * 3);", typeof(TestTwo));

            Console.WriteLine(DateTime.Now - start);

            TestTwo obj = new TestTwo();

            start = DateTime.Now;
            for (int i = 0; i < 100000; i++)
            {
                dm.Invoke(null, new object[] { obj });
            }
            Console.WriteLine(DateTime.Now - start);

            DMCall d = (DMCall)dm.CreateDelegate(typeof(DMCall), obj);

            start = DateTime.Now;
            for (int i = 0; i < 100000; i++)
            {
                d();
            }
            Console.WriteLine(DateTime.Now - start);

            Console.WriteLine(obj.X);
        }
        public static void Main(string[] args)
        {
//			TestOne.Run();
            TestTwo.Run();
//			TestOne.Run();
//			TestTwo.Run();
//			TestOne.Run();
//			TestTwo.Run();
            TestCall.Run();
//			TestPersist.Run();
//			TestCast.Run();
//			TestInvoke.Run();
            TestScope.Run();
        }
Пример #3
0
        public static void Run()
        {
            Console.WriteLine("2)");

            DateTime start = DateTime.Now;
            DynamicMethod dm = Util.Compile("X = abs((5 - Y) * 3);", typeof(TestTwo));
            Console.WriteLine(DateTime.Now - start);

            TestTwo obj = new TestTwo();

            start = DateTime.Now;
            for (int i = 0; i < 100000; i++)
                dm.Invoke(null, new object[] { obj });
            Console.WriteLine(DateTime.Now - start);

            DMCall d = (DMCall) dm.CreateDelegate(typeof(DMCall), obj);

            start = DateTime.Now;
            for (int i = 0; i < 100000; i++)
                d();
            Console.WriteLine(DateTime.Now - start);

            Console.WriteLine(obj.X);
        }