D 50% slower than C++. What I'm doing wrong?

ReneSac reneduani at yahoo.com.br
Sat Apr 14 18:51:59 PDT 2012


I tested the q66 version in my computer (sandy bridge @ 4.3GHz). 
Repeating the old timmings here, and the new results are marked 
as "D-v2":

test.fpaq0 (16562521 bytes) -> test.bmp (33159254 bytes)

Lang| Comp  | Binary size | Time (lower is better)
C++  (g++)  -      13kb   -  2.42s  (100%)   -O3 -s
D    (DMD)  -     230kb   -  4.46s  (184%)   -O -release -inline
D    (GDC)  -    1322kb   -  3.69s  (152%)   -O3 -frelease -s
D-v2 (DMD)  -     206kb   -  4.50s  (186%)   -O -release -inline
D-v2 (GDC)  -     852kb   -  3.65s  (151%)   -O3 -frelease -s

So, basically the same thing... Not using clases seems a little 
slower on DMD, and no difference on GDC. The "if (++ct[cxt][y] > 
65534)" made a very small, but measurable difference (those .04s 
in GDC). The "if ((cxt += cxt + y) >= 512)" only made the code 
more complicated, with no speed benefit.

But the input file is also important. The file you tested seems 
to be an already compressed one, or something not very 
compressible. Here a test with an incompressible file:

pnad9huff.fpaq0 (43443040 bytes) -> test-d.huff (43617049 bytes)

C++  (g++)  -      13kb   -  5.13   (100%)   -O3 -s
D-v2 (DMD)  -     206kb   -  8.03   (156%)   -O -release -inline
D-v2 (GDC)  -     852kb   -  7.09   (138%)   -O3 -frelease -s
D-inl(DMD)  -     228kb   -  6.93   (135%)   -O -release -inline
D-inl(GDC)  -    1318kb   -  6.86   (134%)   -O3 -frelease -s

The C++ advantage becomes smaller in this file. D-inl is my 
manual inline version, with your small optimization on 
"Predictor.Update()".

On Saturday, 14 April 2012 at 19:51:21 UTC, Joseph Rushton 
Wakeling wrote:
> GDC has all the regular gcc optimization flags available IIRC.  
> The ones on the GDC man page are just the ones specific to GDC.
I'm not talking about compiler flags, but the "inline" keyword in 
the C++ source code. I saw some discussion about "@inline" but it 
seems not implemented (yet?). Well, that is not a priority for D 
anyway.


About compiler optimizations, -finline-functions and -fweb are 
part of -O3. I tried to compile with -no-bounds-check, but made 
no diference for DMD and GDC. It probably is part of -release as 
q66 said.


More information about the Digitalmars-d-learn mailing list