Simple performance question from a newcomer

sigod via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 22 11:22:56 PST 2016


On Sunday, 21 February 2016 at 16:20:30 UTC, bachmeier wrote:
> On Sunday, 21 February 2016 at 14:32:15 UTC, dextorious wrote:
>> I had heard while reading up on the language that in D 
>> explicit loops are generally frowned upon and not necessary 
>> for the usual performance reasons.
>
> First, a minor point, the D community is usually pretty careful 
> not to frown on a particular coding style (unlike some 
> communities) so if you are comfortable writing loops and it 
> gives you the fastest code, you should do so.
>
> On the performance issue, you can see this related post about 
> performance with reduce:
> http://forum.dlang.org/post/mailman.4829.1434623275.7663.digitalmars-d@puremagic.com
>
> This was Walter's response:
> http://forum.dlang.org/post/mlvb40$1tdf$1@digitalmars.com
>
> And this shows that LDC flat out does a better job of 
> optimization in this case:
> http://forum.dlang.org/post/mailman.4899.1434779705.7663.digitalmars-d@puremagic.com

I can't agree with that. Between `for` and `foreach` you should 
choose one that is more readable/understandable for particular 
situation. It's compiler's task to optimize such small things.


More information about the Digitalmars-d-learn mailing list