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

bearophile bearophileHUGS at lycos.com
Tue Apr 24 15:13:15 PDT 2012


Marco Leise:

> I ported fast paq8 (fp8) to D, and with some careful 
> D-ification and optimization it runs a bit faster than the 
> original C program when compiled with the GCC on Linux x86_64, 
> Core 2 Duo.

I guess you mean GDC.
With DMD, even if you are a good D programmer, it's not easy to 
beat that original C compressor :-)
Do you have a link to your D version?
Matt Mahoney is probably willing to put a link in his site to 
your D version.


> I don't know about this version of paq you ported the coder 
> from,

It was a very basic coder.


>   The D GC on the other hand allocates that memory and writes 
> zeroes to it immediately.

Is this always done the first time the memory is allocated by the 
GC?


>   The effect is two fold: First, the calloc version will use 
> much less RAM, if
>   the 'allocated' buffers aren't fully used (e.g. you 
> compressed a small file).

On the other hand in D you may allocate the memory in a more 
conscious way.


> "static assert(Foo.sizeof == 64);" helped me find a bug there 
> that
>   resulted from switching from C bitfields to the D version 
> (which is a library
>   solution in Phobos).

The Phobos D bitfields aren't required to mimic C, but that's an 
interesting case. Maybe it's a difference interesting to be taken 
a look at. Do you have the code of the two C-D versions?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list