From: Levente Farkas (lfarkas_at_[hidden])
Date: 2001-10-03 08:40:22
Levente Farkas wrote:
> Eric Ford wrote:
> > > I'm just look into the normal_distribution.hpp and see it's use sin
> > and
> > > cos for calculating the result (use the Box-Muller Method), altough
> > it
> > > 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
> > mail).
> > 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.
ok. so it's realy depend...
orig means the current implementation of normal_distribution
new means my modified normal_distribution
this is runnig time so smaller are better
I measure the following:
on RedHat Linux 7.0, kernel-2.2.19-7.0.8smp, glibc-2.2.3-12, gcc-2.96-93
STLport-4.5-1 on dual PIII-450
gcc -O3 -nostdinc++ -I/usr/include/stlport -I../boost_1_25_0/ rand.cpp
lagged_fibonacci607 7.15 5.15
minstd_rand 8.41 7.51
mt19937 7.25 5.65
on win98 PII-350 with MSVC 6sp4 release version:
lagged_fibonacci607 3.58 4.18
minstd_rand 6.35 8.24
mt19937 3.79 4.62
so the current version is better on windows, but the new version are
faster on linux. it's intresting on slower processor the msvc still
generate a faster code:-(((
> > 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.
so may be it'd be useful to include both version somehow. who is in
-- 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