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

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Sat Apr 14 19:56:09 PDT 2012


> 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.

Ah yes, you're right.  I do wonder if your seeming speed differences are 
magnified because the whole operation is only 2-4 seconds long: if your 
algorithm were operating over a longer timeframe I think you'd likely find the 
relative speed differences decrease.  (I have a memory of a program that took 
~0.004s with a C/C++ version and 1s with D, and the difference seemed to be just 
startup time for the D program.)

What really amazes me is the difference between g++, DMD and GDC in size of the 
executable binary.  100 orders of magnitude!

3 remarks about the D code.  One is that much of it still seems very "C-ish"; 
I'd be interested to see how speed and executable size differ if things like the 
file opening, or the reading of characters, are done with more idiomatic D code. 
  Sounds stupid as the C stuff should be fastest, but I've been surprised 
sometimes at how using idiomatic D formulations can improve things.

Second remark is more of a query -- can Predictor.p() and .update really be 
marked as pure?  Their result for a given input actually varies depending on the 
current values of cxt and ct, which are modified outside of function scope.

Third remark -- again a query -- why the GC.disable ... ?


More information about the Digitalmars-d-learn mailing list