public static SelectableList <TestResult> Test(int c = 100000) { var list = new SelectableList <TestResult>(); var test = new TestClass(); var aTest = test as TestAbstract; var iTest = test as IOrder; var pOrder = test.GetType().GetProperty("Order"); var pItem = test.GetType().GetProperty("Item", new Type[] { typeof(string) }); var cDefault = typeof(TestClass).GetConstructor(Type.EmptyTypes); var cParam = typeof(TestClass).GetConstructor(new Type[] { typeof(int), typeof(string) }); var aOrder = EmitInvoker.Initialize(pOrder); var aItem = EmitInvoker.Initialize(pItem, "fdsfds"); var aDefault = EmitInvoker.Initialize(cDefault); var aParam = EmitInvoker.Initialize(cParam); var param = new object[] { "cfsdf" }; var paramDefault = new object[] { }; var paramParam = new object[] { 12, "1dasdas" }; var actionBinder = new ActionInvoker <TestClass, int>( nameof(TestClass.Order), (item) => item.Order, (item, value) => item.Order = value); int val; string sval; object oval; Stopwatch watch = new Stopwatch(); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { val = actionBinder.GetValue(test); //tc.Order = val; } watch.Stop(); list.Add(new TestResult("Property Get", "Action", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { val = test.Order; //tc.Order = val; } watch.Stop(); list.Add(new TestResult("Property Get", "Direct", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { val = aTest.Order; //tc.Order = val; } watch.Stop(); list.Add(new TestResult("Property Get", "Abstract", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { val = iTest.Order; //tc.Order = val; } watch.Stop(); list.Add(new TestResult("Property Get", "Interface", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { oval = pOrder.GetValue(test, null); } watch.Stop(); list.Add(new TestResult("Property Get", "Reflection", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { val = (int)pOrder.GetValue(test, null); } watch.Stop(); list.Add(new TestResult("Property Get", "Reflection UNBOX", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { oval = aOrder.GetValue(test); } watch.Stop(); list.Add(new TestResult("Property Get", "Emit Invoke", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { val = (int)aOrder.GetValue(test); } watch.Stop(); list.Add(new TestResult("Property Get", "Emit Invoke UNBOX", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { sval = test["fsdfdsf"]; } watch.Stop(); list.Add(new TestResult("Property Index", "Direct", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { oval = pItem.GetValue(test, param); } watch.Stop(); list.Add(new TestResult("Property Index", "Reflection", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { sval = (string)pItem.GetValue(test, param); } watch.Stop(); list.Add(new TestResult("Property Index", "Reflection UNBOX", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { oval = aItem.GetValue(test); } watch.Stop(); list.Add(new TestResult("Property Index", "Emit Invoke", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { sval = (string)aItem.GetValue(test); } watch.Stop(); list.Add(new TestResult("Property Index", "Emit Invoke UNBOX", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { test = new TestClass(); } watch.Stop(); list.Add(new TestResult("Constructor", "Direct", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { test = (TestClass)cDefault.Invoke(paramDefault); } watch.Stop(); list.Add(new TestResult("Constructor", "Reflection UNBOX", watch.Elapsed)); watch.Reset(); watch.Start(); //object[] obj = new object[] { }; for (int i = 0; i <= c; i++) { test = (TestClass)aDefault.Create(paramDefault); } watch.Stop(); list.Add(new TestResult("Constructor", "Emit Invoke UNBOX", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { test = new TestClass(12, "dsadas"); } watch.Stop(); list.Add(new TestResult("Constructor Params", "Direct", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { oval = cParam.Invoke(paramParam); } watch.Stop(); list.Add(new TestResult("Constructor Params", "Reflection", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { test = (TestClass)cParam.Invoke(paramParam); } watch.Stop(); list.Add(new TestResult("Constructor Params", "Reflection UNBOX", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { oval = aParam.Create(paramParam); } watch.Stop(); list.Add(new TestResult("Constructor Params", "Emit Invoke", watch.Elapsed)); watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { test = (TestClass)aParam.Create(paramParam); } watch.Stop(); list.Add(new TestResult("Constructor Params", "Emit Invoke UNBOX", watch.Elapsed)); TestClass p1 = new TestClass(123112365, "test string compa3rision"); TestClass p2 = new TestClass(124312312, "test string comp4arision"); //Compare string watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { p1.Comment.CompareTo(p2.Comment); } watch.Stop(); list.Add(new TestResult("Compare String", "Direct", watch.Elapsed)); //Compare string Invariant watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { CultureInfo.InvariantCulture.CompareInfo.Compare(p1.Comment, p2.Comment, CompareOptions.Ordinal); } watch.Stop(); list.Add(new TestResult("Compare String", "Direct Invariant", watch.Elapsed)); //Compare Accessor string watch.Reset(); watch.Start(); var ce = new InvokerComparer(EmitInvoker.Initialize(typeof(TestClass).GetProperty("Comment")), ListSortDirection.Ascending); for (int i = 0; i <= c; i++) { ce.Compare(p1, p2); } watch.Stop(); list.Add(new TestResult("Compare String", "Emit Invoke Property", watch.Elapsed)); //Compare integer watch.Reset(); watch.Start(); for (int i = 0; i <= c; i++) { p1.Order.CompareTo(p2.Order); } watch.Stop(); list.Add(new TestResult("Compare Int", "Direct", watch.Elapsed)); //Compare Accessor Int watch.Reset(); watch.Start(); ce = new InvokerComparer(EmitInvoker.Initialize(typeof(TestClass).GetProperty("Order")), ListSortDirection.Ascending); for (int i = 0; i <= c; i++) { ce.Compare(p1, p2); } watch.Stop(); list.Add(new TestResult("Compare Int", "Emit Invoke Property", watch.Elapsed)); return(list); }