Beispiel #1
0
        private static void CompareReflectAndEmitBinding()
        {
            const int count = 2000;

            Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine("\n=======  Compare Reflect and Emit Binding performance =======");

            var viewModels = new TestViewModel[count];
            var viewModel2s = new TestViewModel2[count];

            DynamicEngine.SetBindingManager(new ReflectManager());

            for (int i = 0; i < count; i++)
            {
                var viewModel2 = new TestViewModel2();
                var viewModel = new TestViewModel();
                viewModels[i] = viewModel;
                viewModel2s[i] = viewModel2;

                BindingEngine.SetPropertyBinding(viewModel2, testView => testView.Age, viewModel, model => model.Age);
            }

            var sw = new Stopwatch();
            sw.Reset();
            sw.Start();

            for (int i = 0; i < count; i++)
            {
                viewModels[i].Age = i;
            }

            sw.Stop();

            Console.ForegroundColor = ConsoleColor.White;
            System.Console.WriteLine("Reflect manager time elapsed {0}", sw.ElapsedMilliseconds);

            DynamicEngine.SetBindingManager(new EmitManager());

            for (int i = 0; i < count; i++)
            {
                var viewModel2 = new TestViewModel2();
                var viewModel = new TestViewModel();
                viewModels[i] = viewModel;
                viewModel2s[i] = viewModel2;

                BindingEngine.SetPropertyBinding(viewModel2, testView => testView.Age, viewModel, model => model.Age);
            }

            sw = new Stopwatch();
            sw.Reset();
            sw.Start();

            for (int i = 0; i < count; i++)
            {
                viewModels[i].Age = i;
            }

            sw.Stop();

            Console.ForegroundColor = ConsoleColor.Yellow;
            System.Console.WriteLine("Emit manager time elapsed {0}", sw.ElapsedMilliseconds);
        }
Beispiel #2
0
        private static void CompareReflectAndEmitBinding()
        {
            const int count = 2000;

            Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine("\n=======  Compare Reflect and Emit Binding performance =======");


            var viewModels  = new TestViewModel[count];
            var viewModel2s = new TestViewModel2[count];

            DynamicEngine.SetBindingManager(new ReflectManager());

            for (int i = 0; i < count; i++)
            {
                var viewModel2 = new TestViewModel2();
                var viewModel  = new TestViewModel();
                viewModels[i]  = viewModel;
                viewModel2s[i] = viewModel2;

                BindingEngine.SetPropertyBinding(viewModel2, testView => testView.Age, viewModel, model => model.Age);
            }

            var sw = new Stopwatch();

            sw.Reset();
            sw.Start();

            for (int i = 0; i < count; i++)
            {
                viewModels[i].Age = i;
            }

            sw.Stop();

            Console.ForegroundColor = ConsoleColor.White;
            System.Console.WriteLine("Reflect manager time elapsed {0}", sw.ElapsedMilliseconds);

            DynamicEngine.SetBindingManager(new EmitManager());

            for (int i = 0; i < count; i++)
            {
                var viewModel2 = new TestViewModel2();
                var viewModel  = new TestViewModel();
                viewModels[i]  = viewModel;
                viewModel2s[i] = viewModel2;

                BindingEngine.SetPropertyBinding(viewModel2, testView => testView.Age, viewModel, model => model.Age);
            }

            sw = new Stopwatch();
            sw.Reset();
            sw.Start();

            for (int i = 0; i < count; i++)
            {
                viewModels[i].Age = i;
            }

            sw.Stop();

            Console.ForegroundColor = ConsoleColor.Yellow;
            System.Console.WriteLine("Emit manager time elapsed {0}", sw.ElapsedMilliseconds);
        }