Slow performance compared to C++, ideas?

finalpatch fengli at gmail.com
Thu May 30 18:26:10 PDT 2013


Recently I ported a simple ray tracer I wrote in C++11 to D. 
Thanks to the similarity between D and C++ it was almost a line 
by line translation, in other words, very very close. However, 
the D verson runs much slower than the C++11 version. On Windows, 
with MinGW GCC and GDC, the C++ version is twice as fast as the D 
version. On OSX, I used Clang++ and LDC, and the C++11 version 
was 4x faster than D verson.  Since the comparison were between 
compilers that share the same codegen backends I suppose that's a 
relatively fair comparison.  (flags used for GDC: -O3 
-fno-bounds-check -frelease,  flags used for LDC: -O3 -release)

I really like the features offered by D but it's the raw 
performance that's worrying me. From what I read D should offer 
similar performance when doing similar things but my own test 
results is not consistent with this claim. I want to know whether 
this slowness is inherent to the language or it's something I was 
not doing right (very possible because I have only a few days of 
experience with D).

Below is the link to the D and C++ code, in case anyone is 
interested to have a look.

https://dl.dropboxusercontent.com/u/974356/raytracer.d
https://dl.dropboxusercontent.com/u/974356/raytracer.cpp


More information about the Digitalmars-d mailing list