- for loops on List
are a bit more than 2 times cheaper than foreach loops on List . - Looping on array is around 2 times cheaper than looping on List
. - As a consequence, looping on array using for is 5 times cheaper than looping on List
using foreach (which I believe, is what we all do).
jeudi 27 novembre 2008
for versus foreach : an easy and efficient way to improve .NET code performances
In a recent post, Patrick Smacchia shows how the "for" loop is more performant than the foreach one. In many cases the foreach loop simplify the comprehension of algorithms, mainly in complex algorithm. But in small methods or quite straight forward tasks, the use of the "for" can be a huge performance upgrade.
S'abonner à :
Publier des commentaires (Atom)
Aucun commentaire:
Publier un commentaire