Click here to Skip to main content
15,891,713 members
Home / Discussions / C#
   

C#

 
GeneralRe: Do people know about LINQ expression trees for super fast reflection? Pin
SledgeHammer0115-Jan-11 11:23
SledgeHammer0115-Jan-11 11:23 
GeneralRe: Do people know about LINQ expression trees for super fast reflection? Pin
N a v a n e e t h16-Jan-11 4:51
N a v a n e e t h16-Jan-11 4:51 
GeneralRe: Do people know about LINQ expression trees for super fast reflection? Pin
Pete O'Hanlon16-Jan-11 5:06
mvePete O'Hanlon16-Jan-11 5:06 
GeneralRe: Do people know about LINQ expression trees for super fast reflection? Pin
N a v a n e e t h16-Jan-11 5:15
N a v a n e e t h16-Jan-11 5:15 
GeneralRe: Do people know about LINQ expression trees for super fast reflection? Pin
Pete O'Hanlon16-Jan-11 9:12
mvePete O'Hanlon16-Jan-11 9:12 
AnswerAll of this post is plagiarised (except for the smiley...) Pin
Keith Barrow15-Jan-11 11:24
professionalKeith Barrow15-Jan-11 11:24 
AnswerRe: Do people know about LINQ expression trees for super fast reflection? Pin
PIEBALDconsult15-Jan-11 14:10
mvePIEBALDconsult15-Jan-11 14:10 
GeneralRe: Do people know about LINQ expression trees for super fast reflection? [modified] Pin
SledgeHammer0115-Jan-11 15:16
SledgeHammer0115-Jan-11 15:16 
Huh? Cache what?

I don't have production code that goes for (int i = 0; i < 1000000; i++) D'Oh! | :doh: . Its called benchmarking code Big Grin | :-D .

"version 1" didn't cache anything and it took 4.4 seconds to run 1 million times

"version 2" cached the PropertyInfo object and it went down to 2.1 seconds to run 1 million times. I can't cache the propertyInfo.GetValue() call, that would a) defeat the whole point and b) not even work... what if the value changed? How would I get notified in a callback function that it changed? D'Oh! | :doh: And you want me to cache the values of a million objects? D'Oh! | :doh: x 2.

"version 3" went to LINQ expression trees and it went down to 93 milliseconds to run 1 million times. I cached the expression tree, but I did NOT cache the "expressiontree.GetValue()" calls. I still get the same property 1 million times.

4.4 seconds (or to be fair 2.1 seconds) vs 93 milliseconds is not because I'm caching anything.

propertyInfo.GetValue() is an expensive call. It gets the getter method and then calls Invoke on it. I suppose I could have gotten the getter method and cached that, but Invoke is still an expensive call.

The expression tree was simply "inline code" that essentially expanded to:

return (object)((SomeType)o).SomeProperty;

Thats a direct call vs. an invoke.

Thats why its tons faster then reflection.



-- Modified Saturday, January 15, 2011 9:23 PM
GeneralRe: Do people know about LINQ expression trees for super fast reflection? Pin
SledgeHammer0115-Jan-11 15:22
SledgeHammer0115-Jan-11 15:22 
GeneralRe: Do people know about LINQ expression trees for super fast reflection? Pin
PIEBALDconsult16-Jan-11 5:11
mvePIEBALDconsult16-Jan-11 5:11 
AnswerRe: Do people know about LINQ expression trees for super fast reflection? Pin
Dan Mos16-Jan-11 3:00
Dan Mos16-Jan-11 3:00 
AnswerRe: Do people know about LINQ expression trees for super fast reflection? Pin
N a v a n e e t h16-Jan-11 5:14
N a v a n e e t h16-Jan-11 5:14 
GeneralRe: Do people know about LINQ expression trees for super fast reflection? Pin
SledgeHammer0116-Jan-11 7:14
SledgeHammer0116-Jan-11 7:14 
AnswerRe: Do people know about LINQ expression trees for super fast reflection? Pin
jschell17-Jan-11 8:22
jschell17-Jan-11 8:22 
GeneralRe: Do people know about LINQ expression trees for super fast reflection? [modified] Pin
SledgeHammer0118-Jan-11 4:55
SledgeHammer0118-Jan-11 4:55 
Questionhow to convert php code into c sharp code Pin
gsmfather15-Jan-11 8:08
gsmfather15-Jan-11 8:08 
AnswerRe: how to convert php code into c sharp code Pin
dan!sh 15-Jan-11 8:26
professional dan!sh 15-Jan-11 8:26 
AnswerRe: how to convert php code into c sharp code Pin
fjdiewornncalwe15-Jan-11 9:28
professionalfjdiewornncalwe15-Jan-11 9:28 
QuestionC# versus C++, null references and protecting against them Pin
bob1697214-Jan-11 8:48
bob1697214-Jan-11 8:48 
AnswerRe: C# versus C++, null references and protecting against them Pin
Pete O'Hanlon14-Jan-11 9:14
mvePete O'Hanlon14-Jan-11 9:14 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697214-Jan-11 9:58
bob1697214-Jan-11 9:58 
GeneralRe: C# versus C++, null references and protecting against them Pin
Pete O'Hanlon14-Jan-11 10:55
mvePete O'Hanlon14-Jan-11 10:55 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697214-Jan-11 10:48
bob1697214-Jan-11 10:48 
AnswerRe: C# versus C++, null references and protecting against them Pin
jschell14-Jan-11 9:46
jschell14-Jan-11 9:46 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697214-Jan-11 10:23
bob1697214-Jan-11 10:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.