]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/reporting/performance/test_mode.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / math / reporting / performance / test_mode.cpp
1 // (C) Copyright Nick Thompson and Matt Borland 2020.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <random>
7 #include <boost/math/statistics/univariate_statistics.hpp>
8 #include <benchmark/benchmark.h>
9
10 template <class Z>
11 void test_mode(benchmark::State& state)
12 {
13 using boost::math::statistics::sorted_mode;
14
15 std::random_device rd;
16 std::mt19937_64 mt(rd());
17 std::uniform_int_distribution<> dist {1, 10};
18
19 auto gen = [&dist, &mt](){return dist(mt);};
20
21 std::vector<Z> v(state.range(0));
22 std::generate(v.begin(), v.end(), gen);
23
24 for (auto _ : state)
25 {
26 std::vector<Z> modes;
27 benchmark::DoNotOptimize(sorted_mode(v.begin(), v.end(), std::back_inserter(modes)));
28 }
29
30 state.SetComplexityN(state.range(0));
31 }
32
33 template <class Z>
34 void sequential_test_mode(benchmark::State& state)
35 {
36 using boost::math::statistics::sorted_mode;
37
38 std::vector<Z> v(state.range(0));
39
40 size_t current_num {1};
41 // produces {1, 2, 3, 4, 5...}
42 for(size_t i {}; i < v.size(); ++i)
43 {
44 v[i] = current_num;
45 ++current_num;
46 }
47
48 for (auto _ : state)
49 {
50 std::vector<Z> modes;
51 benchmark::DoNotOptimize(sorted_mode(v, std::back_inserter(modes)));
52 }
53
54 state.SetComplexityN(state.range(0));
55 }
56
57 template <class Z>
58 void sequential_pairs_test_mode(benchmark::State& state)
59 {
60 using boost::math::statistics::sorted_mode;
61
62 std::vector<Z> v(state.range(0));
63
64 size_t current_num {1};
65 size_t current_num_counter {};
66 // produces {1, 1, 2, 2, 3, 3, ...}
67 for(size_t i {}; i < v.size(); ++i)
68 {
69 v[i] = current_num;
70 ++current_num_counter;
71 if(current_num_counter > 2)
72 {
73 ++current_num;
74 current_num_counter = 0;
75 }
76 }
77
78 for (auto _ : state)
79 {
80 std::vector<Z> modes;
81 benchmark::DoNotOptimize(sorted_mode(v, std::back_inserter(modes)));
82 }
83
84 state.SetComplexityN(state.range(0));
85 }
86
87 template <class Z>
88 void sequential_multiple_test_mode(benchmark::State& state)
89 {
90 using boost::math::statistics::sorted_mode;
91
92 std::vector<Z> v(state.range(0));
93
94 size_t current_num {1};
95 size_t current_num_counter {};
96 // produces {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, ...}
97 for(size_t i {}; i < v.size(); ++i)
98 {
99 v[i] = current_num;
100 ++current_num_counter;
101 if(current_num_counter > current_num)
102 {
103 ++current_num;
104 current_num_counter = 0;
105 }
106 }
107
108 for (auto _ : state)
109 {
110 std::vector<Z> modes;
111 benchmark::DoNotOptimize(sorted_mode(v, std::back_inserter(modes)));
112 }
113
114 state.SetComplexityN(state.range(0));
115 }
116
117 BENCHMARK_TEMPLATE(test_mode, int32_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
118 BENCHMARK_TEMPLATE(test_mode, int64_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
119 BENCHMARK_TEMPLATE(test_mode, uint32_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
120 BENCHMARK_TEMPLATE(sequential_test_mode, int32_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
121 BENCHMARK_TEMPLATE(sequential_test_mode, int64_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
122 BENCHMARK_TEMPLATE(sequential_test_mode, uint32_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
123 BENCHMARK_TEMPLATE(sequential_pairs_test_mode, int32_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
124 BENCHMARK_TEMPLATE(sequential_pairs_test_mode, int64_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
125 BENCHMARK_TEMPLATE(sequential_pairs_test_mode, uint32_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
126 BENCHMARK_TEMPLATE(sequential_multiple_test_mode, int32_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
127 BENCHMARK_TEMPLATE(sequential_multiple_test_mode, int64_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
128 BENCHMARK_TEMPLATE(sequential_multiple_test_mode, uint32_t)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity();
129
130 BENCHMARK_MAIN();