A peek past lambda
Llewellyn Falco
isidore at setgame.com
Sun Aug 21 05:11:38 PDT 2011
I'm curious as to the following statement:
>
> Lambdas are slow as hell in C#, I don't want to do the same mistake.
>
check out http://diditwith.net/2006/10/05/PerformanceOfForeachVsListForEach.aspx
it would appear they can be are faster than regular blocks of code ?!?
( this seems crazy, but I know I've seen this is java as well, where
the "overhead" of a method call doesn't pan out as expected)
I am wondering if perhaps the lambdas in C# are being confused with
LINQ in C#. Linq can preform slowly, but that isn't because of the
lambdas, it's because of the implementation of linq. A lot of times
people are only using lambdas with linq and start to blur the lines.
Alternatively, performance bottlenecks are also commonly misplaced
when done without a profiler.
My question is, is there a performance difference between
a();
b();
if b is a static method?
is there a performance difference between
a();
otherObject.a();
??
All of the above always struck me as very crazy fast, and if so why
would you add complexity to make lambdas different? It would seem the
only optimization lambdas would benefit from is the realization that
some of them could be a singleton instead of a individual objects.
just spitballing here, but you could solve this one easily by
replacing the " new LambdaAnonymousClass() " call with
"LambdaAnonymousClass.Create()" and then in the creation of the
LambdaAnonymousClass check if there is any Field methods to determine
if it should be a singleton instance or not.
of course this raises an interesting question of the equals() &
hashCode() method, has that been discussed already?
--
Llewellyn Falco
www.approvaltests.com
More information about the lambda-dev
mailing list