Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.

Random Number Library Performance

For some people, performance of random number generation is an important consideration when choosing a random number generator or a particular distribution function. This page provides numerous performance tests with the wide variety of generators and distributions available in the boost library.

The performance has been evaluated on a Pentium Pro 200 MHz with gcc 2.95.2, Linux 2.2.13, glibc 2.1.2. The speed is reported in million random numbers per second (M rn/sec), generated in a tight loop.

Basic Generators

generator M rn/sec time per random number [usec] relative speed compared to fastest [percent]
rand48 5.38 0.183 61%
rand48 run-time configurable 1.48 0.677 17%
lrand48 glibc 2.1.2 1.19 0.843 13%
minstd_rand 2.39 0.318 35%
ecuyer1988 1.12 0.892 13%
kreutzer1986 3.87 0.258 43%
hellekalek1995 (inversive) 0.20 5.12 2%
mt11213b 6.07 0.165 68%
mt19937 6.06 0.165 68%
mt19937 original 5.33 0.188 60%
lagged_fibonacci607 8.90 0.112 100%
lagged_fibonacci4423 8.54 0.117 96%
lagged_fibonacci19937 7.49 0.133 84%
lagged_fibonacci23209 6.63 0.151 74%
lagged_fibonacci44497 4.01 0.250 45%

Note that the lagged Fibonacci generators produce floating-point numbers, whereas all others produce integers.

Distributions

[M rn/sec] minstd_rand kreutzer1986 mt19937 lagged_fibonacci607
uniform_smallint 1.26 1.55 1.93 -
uniform_01 1.79 1.88 3.03 7.74
uniform_real 1.74 1.56 2.34 6.62
geometric 0.593 0.629 0.753 0.916
triangle 0.97 1.02 1.35 1.31
exponential 0.849 0.828 0.887 1.53
normal (polar method) 0.608 0.626 0.738 0.755
lognormal 0.417 0.442 0.470 0.481
uniform_on_sphere 0.154 0.155 0.174 0.218

Note that the lagged Fibonacci generator is at least 2.5 times faster than the Mersenne twister when generating uniformly distributed floating-point numbers. For more sophisticated distributions, the speed improvement is less. Note however that these distributions have not been optimized for speed, yet.


Jens Maurer, 2001-04-15