Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

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 an Intel(R) Core(TM) i7 CPU Q 840 @ 1.87GHz, 1867 Mhz with Visual C++ 2010, Microsoft Windows 7 Professional and with gcc 4.4.5, Ubuntu Linux 2.6.35-25-generic. The speed is reported in million random numbers per second (M rn/sec), generated in a tight loop.

Table 33.13. Basic Generators (Linux)

generator

M rn/sec

time per random number [nsec]

relative speed compared to fastest [percent]

rand48

149.254

6.7

59%

lrand48 run-time

158.73

6.3

63%

minstd_rand0

22.9885

43.5

9%

minstd_rand

22.0751

45.3

8%

ecuyer combined

42.735

23.4

17%

kreutzer1986

151.515

6.6

60%

taus88

250

4

100%

knuth_b

19.6078

51

7%

hellekalek1995 (inversive)

4.54545

220

1%

mt11213b

204.082

4.9

81%

mt19937

204.082

4.9

81%

mt19937_64

60.6061

16.5

24%

lagged_fibonacci607

126.582

7.9

50%

lagged_fibonacci1279

129.87

7.7

51%

lagged_fibonacci2281

129.87

7.7

51%

lagged_fibonacci3217

131.579

7.6

52%

lagged_fibonacci4423

128.205

7.8

51%

lagged_fibonacci9689

128.205

7.8

51%

lagged_fibonacci19937

131.579

7.6

52%

lagged_fibonacci23209

131.579

7.6

52%

lagged_fibonacci44497

131.579

7.6

52%

subtract_with_carry

147.059

6.8

58%

subtract_with_carry_01

105.263

9.5

42%

ranlux3

15.748

63.5

6%

ranlux4

9.11577

109.7

3%

ranlux3_01

10.5708

94.6

4%

ranlux4_01

6.27353

159.4

2%

ranlux64_3

15.8983

62.9

6%

ranlux64_4

9.14913

109.3

3%

ranlux64_3_01

10.9409

91.4

4%

ranlux64_4_01

6.32911

158

2%

ranlux24

15.1976

65.8

6%

ranlux48

8.88099

112.6

3%

mt19937ar.c

111.111

9

44%


Table 33.14. Basic Generators (Windows)

generator

M rn/sec

time per random number [nsec]

relative speed compared to fastest [percent]

rand48

152.672

6.55

64%

lrand48 run-time

24.3724

41.03

10%

minstd_rand0

39.8248

25.11

16%

minstd_rand

39.0778

25.59

16%

ecuyer combined

16.7813

59.59

7%

kreutzer1986

89.0472

11.23

37%

taus88

237.53

4.21

100%

knuth_b

30.8166

32.45

12%

hellekalek1995 (inversive)

5.28457

189.23

2%

mt11213b

237.53

4.21

100%

mt19937

221.239

4.52

93%

mt19937_64

91.5751

10.92

38%

lagged_fibonacci607

142.45

7.02

59%

lagged_fibonacci1279

142.45

7.02

59%

lagged_fibonacci2281

145.56

6.87

61%

lagged_fibonacci3217

149.031

6.71

62%

lagged_fibonacci4423

142.45

7.02

59%

lagged_fibonacci9689

145.773

6.86

61%

lagged_fibonacci19937

142.45

7.02

59%

lagged_fibonacci23209

145.773

6.86

61%

lagged_fibonacci44497

142.45

7.02

59%

subtract_with_carry

136.24

7.34

57%

subtract_with_carry_01

90.3342

11.07

38%

ranlux3

13.1631

75.97

5%

ranlux4

7.60398

131.51

3%

ranlux3_01

8.62738

115.91

3%

ranlux4_01

4.99625

200.15

2%

ranlux64_3

13.1631

75.97

5%

ranlux64_4

7.5861

131.82

3%

ranlux64_3_01

8.63931

115.75

3%

ranlux64_4_01

5.01958

199.22

2%

ranlux24

13.1631

75.97

5%

ranlux48

7.5861

131.82

3%

mt19937ar.c

200.401

4.99

84%


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

Table 33.15. Distributions (Linux)

[M rn/sec]

minstd_rand

kreutzer1986

mt19937

lagged_fibonacci607

uniform_int

16.2338

48.7805

21.5517

23.8663

uniform_smallint

18.9036

114.943

25.3165

74.6269

bernoulli

21.322

85.4701

23.2558

125

geometric

9.42507

11.7925

7.38007

15.528

binomial

13.4953

29.7619

12.7877

38.7597

negative_binomial

1.69549

2.29305

1.65563

2.45098

poisson

13.7552

34.1297

13.369

43.8596

uniform_real

18.2815

44.4444

19.8413

119.048

uniform_01

21.692

72.4638

17.1233

116.279

triangle

15.2207

29.3255

11.9904

51.2821

exponential

10.5374

17.0068

10.8814

22.2222

normal polar

8.82613

12.9199

9.00901

14.771

lognormal

6.15764

7.50188

5.68182

8.61326

chi squared

2.07297

2.8401

2.10926

3.07409

cauchy

9.18274

14.8368

7.37463

17.3913

fisher f

1.04646

1.47449

1.08026

1.61186

student t

1.60927

2.18245

1.65207

2.34192

gamma

2.1097

2.87439

2.13538

3.01296

weibull

4.73709

5.77367

4.20521

6.33312

extreme value

7.40192

10.101

6.23441

11.5741

uniform_on_sphere

2.22222

2.78552

2.28311

2.7933


Table 33.16. Distributions (Windows)

[M rn/sec]

minstd_rand

kreutzer1986

mt19937

lagged_fibonacci607

uniform_int

27.049

79.1139

29.8151

34.8432

uniform_smallint

31.736

90.3342

33.9213

59.9161

bernoulli

25.641

56.2114

27.049

62.8141

geometric

12.8717

18.9645

14.6671

18.5805

binomial

18.2116

32.2165

19.8491

29.4118

negative_binomial

2.79065

3.99138

2.73358

3.72898

poisson

20.0321

37.7074

18.9645

36.4299

uniform_real

27.6319

78.1861

26.4901

71.2251

uniform_01

36.63

95.6938

26.3783

85.4701

triangle

19.4856

43.8982

19.425

36.8324

exponential

17.0474

32.0513

18.005

28.6205

normal polar

14.4051

19.7863

13.1354

20.7426

lognormal

10.8472

13.6968

10.3563

13.7855

chi squared

3.53957

4.95

3.44448

4.83442

cauchy

15.1906

23.5682

14.9768

23.31

fisher f

1.74951

2.45417

1.69854

2.38743

student t

2.63151

3.75291

2.53872

3.51432

gamma

3.50275

4.9729

3.35087

4.75195

weibull

8.96539

11.9161

9.09256

11.6754

extreme value

12.3274

18.4196

12.5945

17.5623

uniform_on_sphere

2.83688

3.58038

2.73898

3.60101



PrevUpHomeNext