D code optimization
Brad Anderson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Sep 22 09:44:15 PDT 2016
On Thursday, 22 September 2016 at 16:09:49 UTC, Sandu wrote:
> It is often being claimed that D is at least as fast as C++.
> Now, I am fairly new to D. But, here is an example where I want
> to see how can this be made possible.
>
> So far my C++ code compiles in ~850 ms.
> While my D code runs in about 2.1 seconds.
>
> [snip]
Just a small tip that applies to both D and C++ in that code. You
can use a static array rather than a dynamically allocated array
in the loop (enum n = 252; then double[n+1] call; in D). You can
also use "double[n+1] call = void;" to mimic C++'s behavior of
uninitialized memory.
Use GDC or LDC when doing performance related work as they
generate faster code typically. I'd be surprised if the C++ and D
code asm wasn't nearly identical for a big chunk of this code
when using GCC/GDC or Clang/LDC.
More information about the Digitalmars-d-learn
mailing list