private static long TestCompiled() { DataTestForPerf src = new DataTestForPerf(); DataTestForPerf dst = new DataTestForPerf(); PropertyInfo piSource = src.GetType().GetProperty("Prop1"); PropertyInfo piDest = dst.GetType().GetProperty("Prop1"); GetHandlerDelegate <int> getSrc = GetSetUtils.CreateGetHandler <int>(piSource); SetHandlerDelegate <int> setDst = GetSetUtils.CreateSetHandler <int>(piDest); src.PropertyChanged += delegate { setDst(dst, getSrc(src)); }; Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 1; i <= NBTURNS; i++) { src.Prop1 = i; } watch.Stop(); return(watch.ElapsedMilliseconds); }
private static long TestReflection() { DataTestForPerf src = new DataTestForPerf(); DataTestForPerf dst = new DataTestForPerf(); PropertyDescriptor pdSource = TypeDescriptor.GetProperties(src)["Prop1"]; PropertyDescriptor pdDest = TypeDescriptor.GetProperties(dst)["Prop1"]; src.PropertyChanged += delegate { pdDest.SetValue(dst, pdSource.GetValue(src)); }; Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 1; i <= NBTURNS; i++) { src.Prop1 = i; } watch.Stop(); return(watch.ElapsedMilliseconds); }