aboutsummaryrefslogtreecommitdiffstats
path: root/util/random/benchmark/prng/main.cpp
blob: 4c3fc3872ee03629f3a40c84bdbc67c5bcabc819 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <library/cpp/testing/benchmark/bench.h>
 
#include <util/random/entropy.h> 
#include <util/random/fast.h> 
#include <util/random/normal.h>
#include <util/random/mersenne.h> 
#include <util/system/compiler.h> 
#include <util/generic/xrange.h>
 
#include <random>

// double part
Y_CPU_BENCHMARK(Mersenne32_Double, p) {
    TMersenne<ui32> rng(Seed());

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;
        Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); 
    } 
} 
 
Y_CPU_BENCHMARK(Mersenne64_Double, p) {
    TMersenne<ui64> rng(Seed());

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;
        Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); 
    } 
} 
 
Y_CPU_BENCHMARK(Fast32_Double, p) {
    TFastRng<ui32> rng(Seed());

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;
        Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); 
    } 
} 
 
Y_CPU_BENCHMARK(Fast64_Double, p) {
    TFastRng<ui64> rng(Seed());

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;
        Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); 
    } 
} 

// integer part
Y_CPU_BENCHMARK(mt19937_32, p) {
    std::mt19937 mt;

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;

        Y_DO_NOT_OPTIMIZE_AWAY(mt());
    }
}

Y_CPU_BENCHMARK(mt19937_64, p) {
    std::mt19937_64 mt;

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;

        Y_DO_NOT_OPTIMIZE_AWAY(mt());
    }
}

Y_CPU_BENCHMARK(Mersenne32_GenRand, p) {
    TMersenne<ui32> rng(Seed());

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;
        Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRand());
    }
}

Y_CPU_BENCHMARK(Mersenne64_GenRand, p) {
    TMersenne<ui64> rng(Seed());

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;
        Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRand());
    }
}

Y_CPU_BENCHMARK(Fast32_GenRand, p) {
    TFastRng<ui32> rng(Seed());

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;
        Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRand());
    }
}

Y_CPU_BENCHMARK(Fast64_GenRand, p) {
    TFastRng<ui64> rng(Seed());

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;
        Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRand());
    }
}

Y_CPU_BENCHMARK(StlNormal, p) {
    TFastRng<ui64> rng(Seed());
    std::normal_distribution<double> d(1.0, 0.0);

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;
        Y_DO_NOT_OPTIMIZE_AWAY(d(rng));
    }
}

Y_CPU_BENCHMARK(UtilNormal, p) {
    TFastRng<ui64> rng(Seed());

    for (auto i : xrange<size_t>(0, p.Iterations())) {
        (void)i;
        Y_DO_NOT_OPTIMIZE_AWAY(NormalDistribution<double>(rng, 1.0, 0.0));
    }
}