Finding large difference b/w execution time of c++ and D codes for same problem

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Feb 12 13:17:24 PST 2013


On Wed, Feb 13, 2013 at 12:56:01AM +0400, Dmitry Olshansky wrote:
> 13-Feb-2013 00:39, Sparsh Mittal пишет:
> >I am finding C++ code is much faster than D code.
> 
> Seems like DMD's floating point issue. The issue being that it
> always works with floats as full-width reals + rounding. Basically
> if nothing changed (and I doubt it changed) then  DMD with floating
> point code is about two (or more) times slower then GDC/LDC.
> 
> The cure is using GDC/LDC compiler as they are pretty stable and up
> to date on the front-end side these days.
[...]

I did a few benchmarks somewhat recently where I compared the
performance of code produced by GDC with DMD. Code produced by GDC
consistently outperforms code produced by DMD by about 20-30% or so.
This is across the board, with both floats, reals, and applications that
don't do heavy arithmetic (just basic looping/recursion constructs).

I didn't investigate in detail the cause of this difference, but the
last time I looked at the assembly code generated by both compilers, I
noticed that GDC's optimizer is far more advanced than DMD's, esp. when
it comes to loop-unrolling, strength reduction, inlining, etc.. For
non-trivial code, GDC pretty much consistently produces superior code in
general (not just in floating-point operations).

So if performance is a concern, I'd say definitely look into GDC or LDC
instead of DMD.


T

-- 
Two wrongs don't make a right; but three rights do make a left...


More information about the Digitalmars-d-learn mailing list