Exemple #1
0
        public void CacheableGetValueTimed()
        {
            var tSetValue = "1";
            var tAnon     = new PropPoco()
            {
                Prop1 = tSetValue
            };


            var tInvoke = new CacheableInvocation(InvocationKind.Get, "Prop1");

            Timer.Action1 = () => { var tOut = tInvoke.Invoke(tAnon); };

            var tPropertyInfo = tAnon.GetType().GetProperty("Prop1");

            Timer.Action2 = () =>
            {
                var tOut = tPropertyInfo.GetValue(tAnon, null);
            };

            var elapsed = Timer.Go(2 * TimeIt.Million);


            Console.WriteLine("Impromptu: " + elapsed.Item1);
            Console.WriteLine("Refelection: " + elapsed.Item2);
            Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed));
            Assert.Less(elapsed.Item1, elapsed.Item2);
        }
        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);
        }
Exemple #3
0
        public void TestToStringProxyDictionaryMassage()
        {
            var tPropPoco = new PropPoco()
            {
                Prop1 = "A"
            };

            dynamic tData = Builder.New().Object(ReturnProp: tPropPoco.ProxyToString(it => "Print Me"));

            IPropPocoProp tInter = Impromptu.ActLike <IPropPocoProp>(tData);

            Assert.AreEqual(tPropPoco.GetType(), tInter.ReturnProp.GetType());
        }
Exemple #4
0
        public void TestToStringProxyConvertImplicit()
        {
            var tAnon = new PropPoco()
            {
                Prop1 = "A", Prop2 = 1
            };

            dynamic tProxy = tAnon.ProxyToString(
                it => string.Format("{0}:{1}", it.Prop1, it.Prop2));

            var tAnon2 = ImplicitCast(tProxy);

            Assert.AreEqual(tAnon.GetType(), tAnon2.GetType());
        }
Exemple #5
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);
        }
        public void TestSetNullTimed()
        {
            var tPoco = new PropPoco();

            String tSetValue = null;

            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);
        }
Exemple #7
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);
        }
        public void TestCacheableSetTimed()
        {
            var tPoco = new PropPoco();

            var tSetValue = "1";

            var tCacheable = new CacheableInvocation(InvocationKind.Set, "Prop1");
            var tWatch = TimeIt.Go(() => tCacheable.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);
        }
Exemple #9
0
        public void CacheableSetNullTimed()
        {
            var tPoco = new PropPoco();

            String tSetValue     = null;
            var    tCachedInvoke = new CacheableInvocation(InvocationKind.Set, "Prop1");

            Timer.Action1 = (() => tCachedInvoke.Invoke(tPoco, tSetValue));
            var tPropertyInfo = tPoco.GetType().GetProperty("Prop1");

            Timer.Action2 = (() => tPropertyInfo.SetValue(tPoco, tSetValue, new object[] { }));

            var elapsed = Timer.Go();

            Console.WriteLine("Impromptu: " + elapsed.Item1);
            Console.WriteLine("Refelection: " + elapsed.Item2);
            Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed));
            Assert.Less(elapsed.Item1, elapsed.Item2);
        }
Exemple #10
0
        public void SetTimed()
        {
#if DEBUG
            Assert.Ignore("Visual Studio slows down dynamic too much in debug mode");
#endif

            var tPoco1    = new PropPoco();
            var tPoco2    = new PropPoco();
            var tSetValue = "1";

            Timer.Action1 = () => Dynamic.InvokeSet(tPoco1, "Prop1", tSetValue);
            var tPropertyInfo = tPoco2.GetType().GetProperty("Prop1");
            Timer.Action2 = () => tPropertyInfo.SetValue(tPoco2, tSetValue, new object[] { });

            var elapsed = Timer.Go(5 * TimeIt.Million);

            Console.WriteLine("Impromptu: " + elapsed.Item1);
            Console.WriteLine("Refelection: " + elapsed.Item2);
            Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed));
            Assert.Less(elapsed.Item1, elapsed.Item2);
        }
Exemple #11
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);
        }
Exemple #12
0
        public void CacheableGetValueTimed()
        {
            var tSetValue = "1";
            var tAnon = new PropPoco() { Prop1 = tSetValue };

            var tInvoke = new CacheableInvocation(InvocationKind.Get, "Prop1");
            Timer.Action1 = () => { var tOut = tInvoke.Invoke(tAnon); };

            var tPropertyInfo = tAnon.GetType().GetProperty("Prop1");
            Timer.Action2 = () =>
                                {
                                    var tOut = tPropertyInfo.GetValue(tAnon, null);
                                };

            var elapsed = Timer.Go(2*TimeIt.Million);

            Console.WriteLine("Impromptu: " + elapsed.Item1);
            Console.WriteLine("Refelection: " + elapsed.Item2);
            Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed));
            Assert.Less(elapsed.Item1, elapsed.Item2);
        }
Exemple #13
0
        public void SetTimed()
        {
            #if DEBUG
            Assert.Ignore("Visual Studio slows down dynamic too much in debug mode");
            #endif

            var tPoco1 = new PropPoco();
            var tPoco2 = new PropPoco();
            var tSetValue = "1";

            Timer.Action1 = () => Dynamic.InvokeSet(tPoco1, "Prop1", tSetValue);
            var tPropertyInfo = tPoco2.GetType().GetProperty("Prop1");
            Timer.Action2 = () => tPropertyInfo.SetValue(tPoco2, tSetValue, new object[] { });

            var elapsed = Timer.Go(5* TimeIt.Million);

            Console.WriteLine("Impromptu: " + elapsed.Item1);
            Console.WriteLine("Refelection: " + elapsed.Item2);
            Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed));
            Assert.Less(elapsed.Item1, elapsed.Item2);
        }
Exemple #14
0
        public void CacheableSetTimed()
        {
            var tPoco1 = new PropPoco();
            var tPoco2 = new PropPoco();

            var tSetValue = "1";

            var tCacheable = new CacheableInvocation(InvocationKind.Set, "Prop1");
            Timer.Action1 = () => tCacheable.Invoke(tPoco1, tSetValue);

            var tPropertyInfo = tPoco2.GetType().GetProperty("Prop1");
            Timer.Action2 = () => tPropertyInfo.SetValue(tPoco2, tSetValue, new object[] { });

            var elapsed = Timer.Go();

            Console.WriteLine("Impromptu: " + elapsed.Item1);
            Console.WriteLine("Refelection: " + elapsed.Item2);
            Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed));
            Assert.Less(elapsed.Item1, elapsed.Item2);
        }
        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);
        }