is D so slow?
fmohamed at mac.com
Mon Jun 16 08:36:28 PDT 2008
On 2008-06-16 16:40:16 +0200, Fawzi Mohamed <fmohamed at mac.com> said:
> On 2008-06-16 16:32:56 +0200, Fawzi Mohamed <fmohamed at mac.com> said:
>> 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
> ehm, sorry...
> You do initialize everything...
> ehm, never post without testing...
I tested... and well I was actually right (I should have trusted my gut
feeling a little more...)
NaN is the culprit.
check your algorithm (you initialize, backwards for some strange
reason) just part of the arrays...
xs = 1.0;
ys = 2.0;
instead of your strange loops, solves everything...
More information about the Digitalmars-d-learn