is D so slow?

Fawzi Mohamed fmohamed at mac.com
Mon Jun 16 07:32:56 PDT 2008


On 2008-06-15 13:53:30 +0200, baleog <maccarka at yahoo.com> said:

> Thank you for your replies! I used malloc instead of new and run time 
> was about 1sec

But you probably did not understand why... and it seems that neither 
did others around here...

Indeed it is a subtle pitfall in which it is easy to fall.

When you benchmark
1) print something depending on the result like the sum of everything 
(it is not the main issue in this case, but doing it would have 
probably shown the problem), so you can also have at least a tiny 
chance to notice if your algorithm is wrong

2) NaNs
operations involving NaNs depending on the IEEE compliance requested on 
the processor can be 1000 times slower!!!!!!!!
D (very thoughtfully, as it makes spotting errors easier) initializes 
the floating point numbers with NaNs (unlike C).
-> your results follow

if you use malloc, the memory is not initialized with NaNs -> performance

manual malloc in this case is definitely not requested

writing a benchmark can be subtle... benchmarking correct code is easier...

Fawzi



More information about the Digitalmars-d-learn mailing list