Simple performance question from a newcomer

Jack Stouffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 21 08:14:03 PST 2016


On Sunday, 21 February 2016 at 14:32:15 UTC, dextorious wrote:
> Now, seeing as how my experience writing D is literally a few 
> hours, is there anything I did blatantly wrong? Did I miss any 
> optimizations? Most importantly, can the elegant operator 
> chaining style be generally made as fast as the explicit loops 
> we've all been writing for decades?

First off, you should really be using GDC or LDC if you want 
speed. On how to do that, see my blog post about here: 
http://jackstouffer.com/blog/nd_slice.html. Specifically the 
section titled "Getting Hands On".

Secondly, both of your other sum examples use naive element by 
element summation rather than the more accurate pairwise 
summation which sum uses with random access floating point 
ranges. So your not really comparing apples to apples here.

Since Phobos' pairwise summation is recursive, it's very likely 
that DMD isn't doing all the optimizations that LDC or GDC can, 
such as inlining or tail call optimizations. I haven't compiled 
your code so I can't check myself.

Also, templates are auto attributed, so there's no reason to 
include @safe nothrow, etc. on templated functions.


More information about the Digitalmars-d-learn mailing list