Created
January 11, 2011 15:50
-
-
Save juanplopes/774594 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo = new Foo(); | |
var bar = typeof(Foo).GetMethod("Bar"); | |
var param = Expression.Parameter(typeof(int)); | |
var bar2 = Expression.Lambda<Func<int, string>>( | |
Expression.Call(Expression.Constant(foo), bar, param), param).Compile(); | |
var s = Stopwatch.StartNew(); | |
for (int i = 0; i < 5000000; i++) | |
foo.Bar(i); | |
Console.WriteLine("Sem reflection: {0}", s.Elapsed); | |
s.Restart(); | |
for (int i = 0; i < 5000000; i++) | |
bar2.Invoke(i); | |
Console.WriteLine("Com reflection: {0}", s.Elapsed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment