Loop optimization

kai kai at nospam.zzz
Fri May 14 08:01:00 PDT 2010


Thanks for the help all!

> 2. Can you use vector operations?  If the example you gave is
> representative of your specific problem, then you can't because you are
> adding overlapping parts of the array.  But if you are doing operations
> on separate arrays, then array operations will be *much* faster.

Unfortunately, I don't think I will be able to. The actual code is
computing norms of a sequence of points and then updating their values as
needed (MLE smoothing/prediction).

> For that evaluation you probably have to use the LDC compiler, that is
> able to optimize better.

I was scared off by the warning that D 2.0 support is experimental. I
realize D 2 itself is still non-production, but for academic interests
industrial-strength isnt all that important if it usually works :).

> Using floating point for indexes and lengths is not a good practice.
> In D large numbers are written like 1_000_000. Use -release too.

Good to know, thanks (thats actually a great feature for scientists!).

> DMD compiler doesn't perform many optimizations, especially on floating
> point computations. But the bigger problem in your code is that you are
> performing operations on NaNs (that's the default initalization of FP
> values in D), and operations on NaNs are usually quite slower.

> in D, the default value for doubles is nan, so you are adding countless
> scores of nan's which is costly for some reason (not a big floating point
> guy, so I'm not sure about this).

Ah ha, that was it-- serves me right for trying to boil down a test case and
failing miserably. I'll head back to my code now and try to find the real
problem :-) At some point I removed the initialization data obviously.


More information about the Digitalmars-d-learn mailing list