On Fri, Nov 14, 2008 at 7:49 AM, Moritz Warning <[EMAIL PROTECTED]> wrote: > On Thu, 13 Nov 2008 06:19:27 -0500, bearophile wrote: > >> In this post I show few things I have found/collected in the last weeks >> related to the performance of the code compiled with DMD. >> > [..] >> >> The D1 docs strongly suggest to use foreach every time it's possible, >> avoiding to use the less handy for(), so for almost a year I have >> assumed foreach is as fast as the for() but this two versions shows >> differences: >> > > I have noticed the same problem with foreach. > A for loop is often faster. :/
One thing to be clear about when talking about the speed of foreach is whether you're using it on a built-in array or on a user type with an opApply. The former is expected to be as fast as for(), the latter is definitely not because it has to call a delegate each time around the loop. --bb
