Sorry, couldn't resist commenting on the term cognitive cruft! I love it! :))

On Wed, Dec 10, 2008 at 12:37, Maciek Sakrejda <[EMAIL PROTECTED]> wrote:
> Interesting. I decided to actually try my test above, and on 1000000
> items, the for-each version takes ~50 milliseconds, versus ~25
> milliseconds for the explicitly indexed loop. When doing some actual
> work in the loop (a trace), the numbers are 41.9 seconds for the
> for-each and 41.1 seconds for the indexed for. On a loop with a trace
> with 100 items, both forms take ~5 milliseconds. This is rather
> unscientific, but I don't have the profiler available (will it ever make
> it to Linux, Adobe?).
>
> So yes, it looks like for-each is a lot slower in some cases, but I'll
> maintain it still probably won't make a difference unless you've got a
> massive loop that does very little, or a deeply nested set of loops.
>
> Consider also the readability and maintainability benefits of a
> for-each: unless you need the index, it's just one more place to
> introduce bugs when refactoring, and it's cognitive cruft when trying to
> follow what's going on.
>
> --
> Maciek Sakrejda
> Truviso, Inc.
> http://www.truviso.com
>

Reply via email to