speed comparison of stl random number generators

In this post we will compare the speed of the different random number engines of the c++ standard template library. All random numbers in this benchmark are created with std::uniform_int_distribution, but with different random number generators. The quality of the random numbers themselves is not considered in this post.

The code for the benchmark can be found here: random_generators_speed.cpp.

I used gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) and an Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz to perform the benchmarks.

Measurements

$ g++ -O3 random_generators_speed.cpp && ./a.out
minstd_rand 12.8 ns per random number
minstd_rand0 12.8 ns per random number
mt19937 17.3 ns per random number
mt19937_64 8.24 ns per random number
ranlux24_base 17.6 ns per random number
ranlux48_base 16.6 ns per random number
ranlux24 72.6 ns per random number
ranlux48 196 ns per random number
knuth_b 18.7 ns per random number
duration per random number of different generators

If only speed is important (and not quality of the random numbers), you should checkout xorshf96 or fastrand.

Hinterlasse einen Kommentar

Erstelle eine Website wie diese mit WordPress.com
Jetzt starten