@@ -27,7 +27,8 @@ public void TestSetTimed()
27
27
var tSetValue = "1" ;
28
28
29
29
var tWatch = TimeIt . Go ( ( ) => Impromptu . InvokeSet ( tPoco , "Prop1" , tSetValue ) , 500000 ) ;
30
- var tWatch2 = TimeIt . Go ( ( ) => tPoco . GetType ( ) . GetProperty ( "Prop1" ) . SetValue ( tPoco , tSetValue , new object [ ] { } ) , 500000 ) ;
30
+ var tPropertyInfo = tPoco . GetType ( ) . GetProperty ( "Prop1" ) ;
31
+ var tWatch2 = TimeIt . Go ( ( ) => tPropertyInfo . SetValue ( tPoco , tSetValue , new object [ ] { } ) , 500000 ) ;
31
32
32
33
Console . WriteLine ( "Impromptu: " + tWatch . Elapsed ) ;
33
34
Console . WriteLine ( "Refelection: " + tWatch2 . Elapsed ) ;
@@ -48,7 +49,12 @@ public void TestPropStaticGetValueTimed()
48
49
49
50
50
51
var tWatch = TimeIt . Go ( ( ) => { var tOut = Impromptu . InvokeGet ( tAnon , "Test" ) ; } , 500000 ) ;
51
- var tWatch2 = TimeIt . Go ( ( ) => { var tOut = tAnon . GetType ( ) . GetProperty ( "Test" ) . GetValue ( tAnon , null ) ; } , 500000 ) ;
52
+
53
+ var tPropertyInfo = tAnon . GetType ( ) . GetProperty ( "Test" ) ;
54
+ var tWatch2 = TimeIt . Go ( ( ) =>
55
+ {
56
+ var tOut = tPropertyInfo . GetValue ( tAnon , null ) ;
57
+ } , 500000 ) ;
52
58
53
59
Console . WriteLine ( "Impromptu: " + tWatch . Elapsed ) ;
54
60
Console . WriteLine ( "Refelection: " + tWatch2 . Elapsed ) ;
@@ -67,7 +73,11 @@ public void TestMethodStaticGetValueTimed()
67
73
68
74
69
75
var tWatch = TimeIt . Go ( ( ) => { var tOut = Impromptu . InvokeMember ( tValue , "ToString" ) ; } , 500000 ) ;
70
- var tWatch2 = TimeIt . Go ( ( ) => { var tOut = tValue . GetType ( ) . GetMethod ( "ToString" , new Type [ ] { } ) . Invoke ( tValue , new object [ ] { } ) ; } , 500000 ) ;
76
+ var tMethodInfo = tValue . GetType ( ) . GetMethod ( "ToString" , new Type [ ] { } ) ;
77
+ var tWatch2 = TimeIt . Go ( ( ) =>
78
+ {
79
+ var tOut = tMethodInfo . Invoke ( tValue , new object [ ] { } ) ;
80
+ } , 500000 ) ;
71
81
72
82
Console . WriteLine ( "Impromptu: " + tWatch . Elapsed ) ;
73
83
Console . WriteLine ( "Refelection: " + tWatch2 . Elapsed ) ;
@@ -84,7 +94,11 @@ public void TestMethodStaticGetValue4argsTimed()
84
94
85
95
86
96
var tWatch = TimeIt . Go ( ( ) => { var tOut = Impromptu . InvokeMember ( tValue , "IndexOf" , "45" , 0 , 14 , StringComparison . InvariantCulture ) ; } , 500000 ) ;
87
- var tWatch2 = TimeIt . Go ( ( ) => { var tOut = tValue . GetType ( ) . GetMethod ( "IndexOf" , new Type [ ] { typeof ( string ) , typeof ( int ) , typeof ( int ) , typeof ( StringComparison ) } ) . Invoke ( tValue , new object [ ] { "45" , 0 , 14 , StringComparison . InvariantCulture } ) ; } , 500000 ) ;
97
+ var tMethodInfo = tValue . GetType ( ) . GetMethod ( "IndexOf" , new Type [ ] { typeof ( string ) , typeof ( int ) , typeof ( int ) , typeof ( StringComparison ) } ) ;
98
+ var tWatch2 = TimeIt . Go ( ( ) =>
99
+ {
100
+ var tOut = tMethodInfo . Invoke ( tValue , new object [ ] { "45" , 0 , 14 , StringComparison . InvariantCulture } ) ;
101
+ } , 500000 ) ;
88
102
89
103
Console . WriteLine ( "Impromptu: " + tWatch . Elapsed ) ;
90
104
Console . WriteLine ( "Refelection: " + tWatch2 . Elapsed ) ;
@@ -101,7 +115,8 @@ public void TestMethodStaticVoidTimed()
101
115
102
116
103
117
var tWatch = TimeIt . Go ( ( ) => Impromptu . InvokeMemberAction ( tValue , "Clear" ) , 500000 ) ;
104
- var tWatch2 = TimeIt . Go ( ( ) => tValue . GetType ( ) . GetMethod ( "Clear" , new Type [ ] { } ) . Invoke ( tValue , new object [ ] { } ) , 500000 ) ;
118
+ var tMethodInfo = tValue . GetType ( ) . GetMethod ( "Clear" , new Type [ ] { } ) ;
119
+ var tWatch2 = TimeIt . Go ( ( ) => tMethodInfo . Invoke ( tValue , new object [ ] { } ) , 500000 ) ;
105
120
106
121
Console . WriteLine ( "Impromptu: " + tWatch . Elapsed ) ;
107
122
Console . WriteLine ( "Refelection: " + tWatch2 . Elapsed ) ;
0 commit comments