Jerry Nixon @Work: Revisiting C# Loop Performance

Jerry Nixon on Windows

Tuesday, February 23, 2010

Revisiting C# Loop Performance

Which is faster? FOR, FOREACH, FOREACHDELEGATE, LINQ, or LAMBDA? And what does all that look like against Parallelism?

Well, I don’t have that last answer just yet. But FOR seems to really TANK. I was surprised. The ForEachDelegate’s victory that surprised me.

I had performed this test before. But the test wasn’t perfect. So, I reworked it. And here is a better version. See the code: http://codepaste.net/sfctyz 

Here are the results:

image

This is with Visual Studio 2008 / .Net 3.5 / and my VPC details are:

image