Monday, October 6, 2008

Performance of foreach vs. List.ForEach

"...when compiling without optimizations, List.ForEach is even faster than a standard for-loop! Of equal interest is to notice that (without compiler optimization) foreach is nearly as fast as a standard for-loop. So, if you're compiling your app without compiler optimizations, List.ForEach is the fastest way to go..."
"...by how must the compiler optimizes for-loops to get more than 50% savings. foreach-loops also get about 20% shaved off. List.ForEach does not receive as much optimization but the important thing to notice is that is still beats foreach-loops by a considerable margin. List.ForEach is faster than a standard for-each loop..."
Complete Article

0 comments: