Performance updates

Moritz Warning moritzwarning at web.de
Thu Nov 13 16:06:07 PST 2008


On Fri, 14 Nov 2008 08:48:53 +0900, Bill Baxter wrote:

> On Fri, Nov 14, 2008 at 7:49 AM, Moritz Warning <moritzwarning at web.de>
> 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.

Nobody would use "for"-loops with opApply in real world code. :P



More information about the Digitalmars-d mailing list