public void DynamicProxyPropertyPerformanceSingleTest() { var holder1 = new PropertyHolder(); var holder2 = new PropertyHolder(); dynamic proxy = new DynamicProxy(holder1); dynamic proxy2 = new DynamicProxy(holder2, false); Stopwatch sw = new Stopwatch(); sw.Start(); proxy.Id = 12; proxy.Name = "Test"; proxy.Old = true; sw.Stop(); long ticksFast = sw.ElapsedTicks; sw.Reset(); sw.Start(); proxy2.Id = 12; proxy2.Name = "Test"; proxy2.Old = true; sw.Stop(); long ticksReflection = sw.ElapsedTicks; Debug.WriteLine((ticksFast / ticksReflection)); Assert.IsTrue(ticksFast > ticksReflection); }
public void PropertyAccessorPerformanceTest() { int loopCount = 1000; PropertyHolder ph = new PropertyHolder(); //the slowest one Proxy.FastReflection.PropertyAccessor pa = new Proxy.FastReflection.PropertyAccessor(typeof(PropertyHolder), "Id"); System.Reflection.PropertyInfo pi = typeof(PropertyHolder).GetProperty("Id"); ShareDeployed.Proxy.FastReflection.FastProperty fp = new ShareDeployed.Proxy.FastReflection.FastProperty(pi); ShareDeployed.Proxy.FastReflection.FastProperty<PropertyHolder> fp2 = new Proxy.FastReflection.FastProperty<PropertyHolder>(pi); ShareDeployed.Proxy.FastReflection.FastProperty<PropertyHolder, int> fp3 = new Proxy.FastReflection.FastProperty<PropertyHolder, int>(pi); Stopwatch sw = new Stopwatch(); sw.Start(); int id = 0; for (int i = 1; i <= loopCount; i++) { ph.Id = i; id = ph.Id; } sw.Stop(); long directTime = sw.ElapsedMilliseconds; sw.Reset(); sw.Start(); for (int i = 1; i <= loopCount; i++) { pi.SetValue(ph, i, null); id = (int)pi.GetValue(ph, null); } sw.Stop(); long reflTime = sw.ElapsedMilliseconds; sw.Reset(); sw.Start(); for (int i = 1; i <= loopCount; i++) { pa.Set(ph, i); id = (int)pa.Get(ph); } sw.Stop(); long paTime = sw.ElapsedMilliseconds; sw.Reset(); sw.Start(); for (int i = 1; i <= loopCount; i++) { fp.Set(ph, i); id = (int)fp.Get(ph); } sw.Stop(); long fpTime = sw.ElapsedMilliseconds; sw.Reset(); sw.Start(); for (int i = 1; i <= loopCount; i++) { fp2.Set(ph, i); id = (int)fp2.Get(ph); } sw.Stop(); long fpTime2 = sw.ElapsedMilliseconds; sw.Reset(); sw.Start(); for (int i = 1; i <= loopCount; i++) { fp3.Set(ph, i); id = fp3.Get(ph); } sw.Stop(); long fpTime3 = sw.ElapsedMilliseconds; Debug.WriteLine(string.Format("Difference is:{0},{1},{2},{3},{4},{5}", directTime, reflTime, paTime, fpTime, fpTime2, fpTime3)); Assert.IsTrue(fpTime3 < fpTime && fpTime2 < fpTime); Assert.IsTrue(directTime < paTime && paTime > fpTime && fpTime3 < reflTime); }
public void DynamicProxyPropertyPerformanceMultipleTest() { var holder1 = new PropertyHolder(); var holder2 = new PropertyHolder(); dynamic proxy = new DynamicProxy(holder1); dynamic proxy2 = new DynamicProxy(holder2, false); int iterCount = 10000; Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 1; i <= iterCount; i++) { proxy.Id = i; proxy.Name = "Test"; proxy.Old = true; } sw.Stop(); long ticksFast = sw.ElapsedTicks; sw.Reset(); sw.Start(); for (int i = 1; i <= iterCount; i++) { proxy2.Id = i; proxy2.Name = "Test"; proxy2.Old = true; } sw.Stop(); long ticksReflection = sw.ElapsedTicks; Debug.WriteLine((ticksReflection / ticksFast)); Assert.IsTrue(ticksFast < ticksReflection); }