From: Levente Farkas (lfarkas_at_[hidden])
Date: 2001-10-02 04:03:37
Eric Ford wrote:
> > I'm just look into the normal_distribution.hpp and see it's use sin
> > cos for calculating the result (use the Box-Muller Method), altough
> > can be "faster" with the Polar Method (see eg:
> > http://www.dspguru.com/howto/tech/wgn2.htm)
> > the strange thing that the current version are faster even it use
> > trigonometric functions(?) at least on a PIII with MSVC 6sp4 when
> > I compile release (optimezed) code.
> > (I append the patch which I made for the test at the end of this
> The relative speed of the two methods depends on the speed of the
> RNG. Mercene Twister generates very good RNs, but isn't the fastest.
> I beleive if you substitute a fast RNG, say a linear congruential, the
> loop method is likely to be faster.
but I use both (mt19937, minstd_rand) rng for both moth measurement.
the result is the same the current normal_distribution (Box-Muller Method),
are faster in both case and I don't know why? it seems 4 addition are
more expensive than a sin + a cos??? probably the current code can
be better optimized. anyway linear congruential rngs are slower eg.
minstd_rand almost 2 times slower than mt19937.
> I wouldn't be oppose to boost providing both methods as their relative
> speed can depend on the RNG speed and also how fast the sin and cos
> operations are on different hardware.
I send the patch so one can easily create a new class or another
template parameter for the current normal_distribution class to choose
between the different version.
-- Levente "Si vis pacem para bellum!"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk