Why is this D code slower than C++?
Steve Horne
stephenwantshornenospam100 at aol.com
Wed Jan 17 14:34:31 PST 2007
On Wed, 17 Jan 2007 11:18:10 -0800, Bradley Smith
<digitalmars-com at baysmith.com> wrote:
>Thanks for all the suggestions. It helps, but not enough to make the D
>code faster than the C++. It is now 2.6 times slower. The render times
>are now approx. 13 sec for raytracer_d and approx. 5 sec for raytracer_cpp.
...
>
>Any other suggestions?
I haven't actually looked at the code, but I'll take a guess anyway.
Raytracing is heavy on the floating point math. As Walter Bright
acknowledges, the DMD compiler does not handle the optimisation of
float arithmetic as well as some C++ compilers.
You could try the GNU D compiler - GDC. Since it is using the standard
GNU compiler suite backend code generator, it will probably handle the
optimisation better.
A second option is to split out some key inner-loop calculations and
handle them in C, using D for the less performance-sensitive code.
Calling C code from D is easy enough, though calling C++ is more of a
hassle. This hack could be considered temporary, as the D float
performance will no doubt be improved in time.
Alternatively, if you don't mind losing portability, you could try
using inline assembler for those key inner-loop calculations. If
you're a real speed freak, you might even try using SIMD instructions
to get 4 float calculations per instruction (and IIRC most SIMD
instructions complete in a single clock cycle these days). The down
side to that would be lower floating point precision, but for
raytracing I wouldn't expect that to be a big deal.
--
Remove 'wants' and 'nospam' from e-mail.
More information about the Digitalmars-d-learn
mailing list