예제 #1
0
        public void TestCacheableMethodPocoGetValuePassNullDoubleCallTimed()
        {
            var tValue = new OverloadingMethPoco();

            var tCachedInvoke = new CacheableInvocation(InvocationKind.InvokeMember, "Func", 1);
            var tInteration   = 500000;
            var tWatch        = TimeIt.Go(() =>
            {
                var tOut  = tCachedInvoke.Invoke(tValue, null);
                var tOut2 = tCachedInvoke.Invoke(tValue, 2);
            }, tInteration);

            var tMethodInfo  = tValue.GetType().GetMethod("Func", new Type[] { typeof(object) });
            var tMethodInfo2 = tValue.GetType().GetMethod("Func", new Type[] { typeof(int) });
            var tWatch2      = TimeIt.Go(() =>
            {
                var tOut  = tMethodInfo.Invoke(tValue, new object[] { null });
                var tOut2 = tMethodInfo2.Invoke(tValue, new object[] { 2 });
            }, tInteration);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Reflection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #2
0
        public void TestMethodPocoGetValuePassNullDoubleCallTimed()
        {
#if DEBUG
            Assert.Ignore("Visual Studio slows down dynamic too much in debug mode");
#endif
            var tValue = new OverloadingMethPoco();


            var tInteration = 500000;
            var tWatch      = TimeIt.Go(() => {
                var tOut  = Impromptu.InvokeMember(tValue, "Func", null);
                var tOut2 = Impromptu.InvokeMember(tValue, "Func", 2);
            }, tInteration);

            var tMethodInfo  = tValue.GetType().GetMethod("Func", new Type[] { typeof(object) });
            var tMethodInfo2 = tValue.GetType().GetMethod("Func", new Type[] { typeof(int) });
            var tWatch2      = TimeIt.Go(() =>
            {
                var tOut  = tMethodInfo.Invoke(tValue, new object[] { null });
                var tOut2 = tMethodInfo2.Invoke(tValue, new object[] { 2 });
            }, tInteration);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Reflection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #3
0
        public void SpeedTestInterface()
        {
            dynamic New     = new ClayFactory();
            IRobot  tRobot  = New.Robot().Name("Bender");
            IRobot  tRobotI = Impromptu.ActLike <IRobot>(New.Robot().Name("Bender"));

            var tInteration = 50000;
            var tWatchC     = TimeIt.Go(() =>
            {
                var tOut =
                    Impromptu.ActLike <IRobot>(New.Robot().Name("Bender"));
            }, tInteration);
            var tWatchC2 = TimeIt.Go(() =>
            {
                IRobot tOut = New.Robot().Name("Bender");
            }, tInteration);

            TestContext.WriteLine("*CreateInterface*");
            TestContext.WriteLine("Impromptu: " + tWatchC.Elapsed);
            TestContext.WriteLine("Clay: " + tWatchC2.Elapsed);
            TestContext.WriteLine("Impromptu VS Clay: {0:0.0} x faster", (double)tWatchC2.ElapsedTicks / tWatchC.ElapsedTicks);
            Assert.Less(tWatchC.Elapsed, tWatchC2.Elapsed);

            var tWatch = TimeIt.Go(() => { var tOut = tRobotI.Name; }, tInteration);

            var tWatch2 = TimeIt.Go(() => { var tOut = tRobot.Name; }, tInteration);

            TestContext.WriteLine("*Get from Interface*");
            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Clay: " + tWatch2.Elapsed);

            TestContext.WriteLine("Impromptu VS Clay: {0:0.0} x faster", (double)tWatch2.ElapsedTicks / tWatch.ElapsedTicks);

            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #4
0
        public void TestSetTimed()
        {
            // Compares PB duck-typing with plain reflection and ImpromptuInterfaces (InvokeSet and using an ActLike<> invocation)
            // So far, PB-duck-typing is about twice as slow (when profiled) as II. Perhaps this can get better... Though the penalty
            // may be worth it when considering the extra features (like fuzzy-ducking)
            var tPoco = new PropPoco();

            var tSetValue = "1";

            var tWatch = TimeIt.Go(() =>
            {
                Impromptu.InvokeSet(tPoco, "Prop1", tSetValue);
            }, 500000);
            var tPropertyInfo = tPoco.GetType().GetProperty("Prop1");
            var tWatch2       = TimeIt.Go(() => tPropertyInfo.SetValue(tPoco, tSetValue, new object[] {}), TIMES);
            var ducked        = tPoco.DuckAs <IPropPoco>();

            Assert.IsNotNull(ducked);
            var tWatch3 = TimeIt.Go(() => ducked.Prop1 = tSetValue, TIMES);


            TestContext.WriteLine("InvokeSet: " + tWatch.Elapsed);
            TestContext.WriteLine("Reflection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Ducked: " + tWatch3.Elapsed);
        }
예제 #5
0
        public void TestFastDynamicInvokeAction()
        {
            Action <int> tFunc       = it => it.ToString();
            var          tStopWatch1 = TimeIt.Go(() => tFunc.FastDynamicInvoke(5));

            var tStopWatch2 = TimeIt.Go(() => tFunc.DynamicInvoke(5));

            TestContext.WriteLine("Impromptu: " + tStopWatch1.Elapsed);
            TestContext.WriteLine("Reflection: " + tStopWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tStopWatch2.Elapsed.Ticks / tStopWatch1.Elapsed.Ticks);
            Assert.Less(tStopWatch1.Elapsed, tStopWatch2.Elapsed);
        }
예제 #6
0
        public void TestConstructorTimed()
        {
            var tWatch  = TimeIt.Go(() => { var tOut = Impromptu.InvokeConstructor(typeof(Tuple <string>), "Test"); });
            var tWatch2 = TimeIt.Go(() =>
            {
                var tOut = Activator.CreateInstance(typeof(Tuple <string>), "Test");
            });

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #7
0
        public void TestCachedConstructorValueTypeTimed()
        {
            var tIter         = 1000000;
            var tCachedInvoke = new CacheableInvocation(InvocationKind.Constructor, argCount: 3);
            var tWatch        = TimeIt.Go(() => { var tOut = tCachedInvoke.Invoke(typeof(DateTime), 2010, 1, 20); }, tIter);
            var tWatch2       = TimeIt.Go(() =>
            {
                var tOut = Activator.CreateInstance(typeof(DateTime), 2010, 1, 20);
            }, tIter);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #8
0
        public void TestCacheableSetNullTimed()
        {
            var tPoco = new PropPoco();

            String tSetValue     = null;
            var    tCachedInvoke = new CacheableInvocation(InvocationKind.Set, "Prop1");
            var    tWatch        = TimeIt.Go(() => tCachedInvoke.Invoke(tPoco, tSetValue), 500000);
            var    tPropertyInfo = tPoco.GetType().GetProperty("Prop1");
            var    tWatch2       = TimeIt.Go(() => tPropertyInfo.SetValue(tPoco, tSetValue, new object[] { }), 500000);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #9
0
        public void TestCacheableMethodPocoVoidTimed()
        {
            var tValue = new Dictionary <object, object>();

            var tCachedInvoke = new CacheableInvocation(InvocationKind.InvokeMemberAction, "Clear");

            var tWatch      = TimeIt.Go(() => tCachedInvoke.Invoke(tValue));
            var tMethodInfo = tValue.GetType().GetMethod("Clear", new Type[] { });
            var tWatch2     = TimeIt.Go(() => tMethodInfo.Invoke(tValue, new object[] { }));

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Reflection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #10
0
        public void TestConstructorValueTypeTimed()
        {
            var tIter = 1000000;

            var tWatch  = TimeIt.Go(() => { var tOut = Dynamic.InvokeConstructor(typeof(DateTime), 2010, 1, 20); }, tIter);
            var tWatch2 = TimeIt.Go(() =>
            {
                var tOut = Activator.CreateInstance(typeof(DateTime), 2010, 1, 20);
            }, tIter);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #11
0
        public void TestGetStaticTimed()
        {
            var tStaticType = typeof(DateTime);
            var tTarget     = tStaticType.WithStaticContext();
            var tWatch      = TimeIt.Go(() => { var tOut = Impromptu.InvokeGet(tTarget, "Today"); }, 500000);
            var tMethodInfo = typeof(DateTime).GetProperty("Today").GetGetMethod();
            var tWatch2     = TimeIt.Go(() =>
            {
                var tOut = tMethodInfo.Invoke(tStaticType, new object[] { });
            }, 500000);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #12
0
        public void SpeedTestPrototype()
        {
            dynamic NewI = Builder.New();
            dynamic NewE = Builder.New <ExpandoObject>();
            dynamic NewP = Builder.New <Robot>();
            dynamic NewC = new ClayFactory();

            var   tRobotI = NewI.Robot(Name: "Bender");
            var   tRobotC = NewC.Robot(Name: "Bender");
            var   tRobotE = NewE.Robot(Name: "Bender");
            Robot tRobotP = NewP.Robot(Name: "Bender");

            var tWatchI = TimeIt.Go(() =>
            {
                var tOut = tRobotI.Name;
            });

            var tWatchC = TimeIt.Go(() =>
            {
                var tOut = tRobotC.Name;
            });

            var tWatchE = TimeIt.Go(() =>
            {
                var tOut = tRobotE.Name;
            });

            var tWatchP = TimeIt.Go(() =>
            {
                var tOut = tRobotP.Name;
            });

            TestContext.WriteLine("Impromptu: " + tWatchI.Elapsed);
            TestContext.WriteLine("Clay: " + tWatchC.Elapsed);
            TestContext.WriteLine("Expando: " + tWatchE.Elapsed);
            TestContext.WriteLine("POCO: " + tWatchP.Elapsed);

            Assert.Less(tWatchI.Elapsed, tWatchC.Elapsed);

            TestContext.WriteLine("Impromptu VS Clay: {0:0.0} x faster", (double)tWatchC.ElapsedTicks / tWatchI.ElapsedTicks);
            TestContext.WriteLine("Expando  VS Clay:{0:0.0}  x faster", (double)tWatchC.ElapsedTicks / tWatchE.ElapsedTicks);
            TestContext.WriteLine("POCO  VS Clay:{0:0.0}  x faster", (double)tWatchC.ElapsedTicks / tWatchP.ElapsedTicks);
            TestContext.WriteLine("POCO  VS Impromptu:{0:0.0}  x faster", (double)tWatchI.ElapsedTicks / tWatchP.ElapsedTicks);
            TestContext.WriteLine("POCO  VS Expando:{0:0.0}  x faster", (double)tWatchE.ElapsedTicks / tWatchP.ElapsedTicks);
            TestContext.WriteLine("Expando  VS Impromptu:{0:0.0}  x faster", (double)tWatchI.ElapsedTicks / tWatchE.ElapsedTicks);
        }
예제 #13
0
        public void TestMethodStaticMethodValueTimed()
        {
            var    tStaticType = typeof(DateTime);
            var    tTarget     = tStaticType.WithStaticContext();
            string tDate       = "01/20/2009";
            var    tWatch      = TimeIt.Go(() => { var tOut = Impromptu.InvokeMember(tTarget, "Parse", tDate); }, 500000);
            var    tMethodInfo = typeof(DateTime).GetMethod("Parse", new[] { typeof(string) });
            var    tWatch2     = TimeIt.Go(() =>
            {
                var tOut = tMethodInfo.Invoke(tStaticType, new object[] { tDate });
            }, 500000);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #14
0
        public void TestSetTimed()
        {
            var tPoco = new PropPoco();

            var tSetValue = "1";

            var tWatch        = TimeIt.Go(() => Impromptu.InvokeSet(tPoco, "Prop1", tSetValue), 500000);
            var tPropertyInfo = tPoco.GetType().GetProperty("Prop1");
            var tWatch2       = TimeIt.Go(() => tPropertyInfo.SetValue(tPoco, tSetValue, new object[] { }), 500000);



            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #15
0
        public void TestMethodPocoGetValue4argsTimed()
        {
            var tValue = "test 123 45 string";



            var tWatch      = TimeIt.Go(() => { var tOut = Impromptu.InvokeMember(tValue, "IndexOf", "45", 0, 14, StringComparison.InvariantCulture); }, 500000);
            var tMethodInfo = tValue.GetType().GetMethod("IndexOf", new Type[] { typeof(string), typeof(int), typeof(int), typeof(StringComparison) });
            var tWatch2     = TimeIt.Go(() =>
            {
                var tOut = tMethodInfo.Invoke(tValue, new object[] { "45", 0, 14, StringComparison.InvariantCulture });
            }, 500000);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Reflection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #16
0
        public void TestCacheableMethodPocoGetValueTimed()
        {
            var tValue = 1;


            var tCachedInvoke = new CacheableInvocation(InvocationKind.InvokeMember, "ToString");
            var tWatch        = TimeIt.Go(() => { var tOut = tCachedInvoke.Invoke(tValue); }, 500000);
            var tMethodInfo   = tValue.GetType().GetMethod("ToString", new Type[] { });
            var tWatch2       = TimeIt.Go(() =>
            {
                var tOut = tMethodInfo.Invoke(tValue, new object[] { });
            }, 500000);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #17
0
        public void TestCacheableMethodStaticMethodValueTimed()
        {
            var    tStaticType = typeof(DateTime);
            var    tContext    = new StaticContext(tStaticType);
            string tDate       = "01/20/2009";

            var tCachedInvoke = new CacheableInvocation(InvocationKind.InvokeMember, "Parse", argCount: 1,
                                                        context: tContext);
            var tWatch      = TimeIt.Go(() => { var tOut = tCachedInvoke.Invoke(tStaticType, tDate); }, 500000);
            var tMethodInfo = typeof(DateTime).GetMethod("Parse", new[] { typeof(string) });
            var tWatch2     = TimeIt.Go(() =>
            {
                var tOut = tMethodInfo.Invoke(tStaticType, new object[] { tDate });
            }, 500000);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #18
0
        public void TestPropPocoGetValueTimed()
        {
            var tSetValue = "1";
            var tAnon     = new { Test = tSetValue };



            var tWatch = TimeIt.Go(() => { var tOut = Impromptu.InvokeGet(tAnon, "Test"); }, 500000);

            var tPropertyInfo = tAnon.GetType().GetProperty("Test");
            var tWatch2       = TimeIt.Go(() =>
            {
                var tOut = tPropertyInfo.GetValue(tAnon, null);
            }, 500000);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #19
0
        public void TestConstructorNoARgTimed()
        {
            var tWatch  = TimeIt.Go(() => { var tOut = Impromptu.InvokeConstructor(typeof(List <string>)); });
            var tWatch2 = TimeIt.Go(() =>
            {
                var tOut = Activator.CreateInstance(typeof(List <string>));
            });
            var tWatch3 = TimeIt.Go(() =>
            {
                var tOut = Activator.CreateInstance <List <string> >();
            });

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Refelection Generic: " + tWatch3.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);

            Assert.Ignore("I don't think this is beatable at the moment");
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #20
0
        public void TestCacheableGetStaticTimed()
        {
            var tStaticType   = typeof(DateTime);
            var tContext      = new StaticContext(tStaticType);
            var tCachedInvoke = new CacheableInvocation(InvocationKind.Get, "Today", context: tContext);

            var tWatch = TimeIt.Go(() =>
            {
                var tOut = tCachedInvoke.Invoke(tStaticType);
            }, 500000);
            var tMethodInfo = typeof(DateTime).GetProperty("Today").GetGetMethod();

            var tWatch2 = TimeIt.Go(() =>
            {
                var tOut = tMethodInfo.Invoke(tStaticType, new object[] { });
            }, 500000);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
예제 #21
0
        public void TestCacheableGetValueTimed()
        {
            var tSetValue = "1";
            var tAnon     = new PropPoco()
            {
                Prop1 = tSetValue
            };


            var tInvoke = new CacheableInvocation(InvocationKind.Get, "Prop1");
            var tWatch  = TimeIt.Go(() => { var tOut = tInvoke.Invoke(tAnon); }, 500000);

            var tPropertyInfo = tAnon.GetType().GetProperty("Prop1");
            var tWatch2       = TimeIt.Go(() =>
            {
                var tOut = tPropertyInfo.GetValue(tAnon, null);
            }, 500000);

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Refelection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }