]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/benchmark/histogram_filling.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / histogram / benchmark / histogram_filling.cpp
1 // Copyright 2015-2019 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <benchmark/benchmark.h>
8 #include <boost/histogram/axis/regular.hpp>
9 #include <boost/histogram/storage_adaptor.hpp>
10 #include <memory>
11 #include "../test/throw_exception.hpp"
12 #include "../test/utility_histogram.hpp"
13 #include "generator.hpp"
14
15 #include <boost/assert.hpp>
16 struct assert_check {
17 assert_check() {
18 BOOST_ASSERT(false); // don't run with asserts enabled
19 }
20 } _;
21
22 using SStore = std::vector<double>;
23
24 // make benchmark compatible with older versions of the library
25 #if __has_include(<boost/histogram/unlimited_storage.hpp>)
26 #include <boost/histogram/unlimited_storage.hpp>
27 using DStore = boost::histogram::unlimited_storage<>;
28 #else
29 #include <boost/histogram/adaptive_storage.hpp>
30 using DStore = boost::histogram::adaptive_storage<>;
31 #endif
32
33 using namespace boost::histogram;
34 using reg = axis::regular<>;
35
36 template <class Distribution, class Tag, class Storage = SStore>
37 static void fill_1d(benchmark::State& state) {
38 auto h = make_s(Tag(), Storage(), reg(100, 0, 1));
39 auto gen = generator<Distribution>();
40 for (auto _ : state) benchmark::DoNotOptimize(h(gen()));
41 state.SetItemsProcessed(state.iterations());
42 }
43
44 template <class Distribution, class Tag, class Storage = SStore>
45 static void fill_n_1d(benchmark::State& state) {
46 auto h = make_s(Tag(), Storage(), reg(100, 0, 1));
47 auto gen = generator<Distribution>();
48 for (auto _ : state) h.fill(gen);
49 state.SetItemsProcessed(state.iterations() * gen.size());
50 }
51
52 template <class Distribution, class Tag, class Storage = SStore>
53 static void fill_2d(benchmark::State& state) {
54 auto h = make_s(Tag(), Storage(), reg(100, 0, 1), reg(100, 0, 1));
55 auto gen = generator<Distribution>();
56 for (auto _ : state) benchmark::DoNotOptimize(h(gen(), gen()));
57 state.SetItemsProcessed(state.iterations() * 2);
58 }
59
60 template <class Distribution, class Tag, class Storage = SStore>
61 static void fill_n_2d(benchmark::State& state) {
62 auto h = make_s(Tag(), Storage(), reg(100, 0, 1), reg(100, 0, 1));
63 auto gen = generator<Distribution>();
64 auto v = {gen, gen};
65 for (auto _ : state) h.fill(v);
66 state.SetItemsProcessed(state.iterations() * 2 * gen.size());
67 }
68
69 template <class Distribution, class Tag, class Storage = SStore>
70 static void fill_3d(benchmark::State& state) {
71 auto h = make_s(Tag(), Storage(), reg(100, 0, 1), reg(100, 0, 1), reg(100, 0, 1));
72 auto gen = generator<Distribution>();
73 for (auto _ : state) benchmark::DoNotOptimize(h(gen(), gen(), gen()));
74 state.SetItemsProcessed(state.iterations() * 3);
75 }
76
77 template <class Distribution, class Tag, class Storage = SStore>
78 static void fill_n_3d(benchmark::State& state) {
79 auto h = make_s(Tag(), Storage(), reg(100, 0, 1), reg(100, 0, 1), reg(100, 0, 1));
80 auto gen = generator<Distribution>();
81 auto v = {gen, gen, gen};
82 for (auto _ : state) h.fill(v);
83 state.SetItemsProcessed(state.iterations() * 3 * gen.size());
84 }
85
86 template <class Distribution, class Tag, class Storage = SStore>
87 static void fill_6d(benchmark::State& state) {
88 auto h = make_s(Tag(), Storage(), reg(10, 0, 1), reg(10, 0, 1), reg(10, 0, 1),
89 reg(10, 0, 1), reg(10, 0, 1), reg(10, 0, 1));
90 auto gen = generator<Distribution>();
91 for (auto _ : state)
92 benchmark::DoNotOptimize(h(gen(), gen(), gen(), gen(), gen(), gen()));
93 state.SetItemsProcessed(state.iterations() * 6);
94 }
95
96 template <class Distribution, class Tag, class Storage = SStore>
97 static void fill_n_6d(benchmark::State& state) {
98 auto h = make_s(Tag(), Storage(), reg(10, 0, 1), reg(10, 0, 1), reg(10, 0, 1),
99 reg(10, 0, 1), reg(10, 0, 1), reg(10, 0, 1));
100 auto gen = generator<Distribution>();
101 auto v = {gen, gen, gen, gen, gen, gen};
102 for (auto _ : state) h.fill(v);
103 state.SetItemsProcessed(state.iterations() * 6 * gen.size());
104 }
105
106 BENCHMARK_TEMPLATE(fill_1d, uniform, static_tag);
107 // BENCHMARK_TEMPLATE(fill_1d, uniform, static_tag, DStore);
108 BENCHMARK_TEMPLATE(fill_1d, normal, static_tag);
109 // BENCHMARK_TEMPLATE(fill_1d, normal, static_tag, DStore);
110 BENCHMARK_TEMPLATE(fill_1d, uniform, dynamic_tag);
111 // BENCHMARK_TEMPLATE(fill_1d, uniform, dynamic_tag, DStore);
112 BENCHMARK_TEMPLATE(fill_1d, normal, dynamic_tag);
113 // BENCHMARK_TEMPLATE(fill_1d, normal, dynamic_tag, DStore);
114
115 BENCHMARK_TEMPLATE(fill_n_1d, uniform, static_tag);
116 // BENCHMARK_TEMPLATE(fill_n_1d, uniform, static_tag, DStore);
117 BENCHMARK_TEMPLATE(fill_n_1d, normal, static_tag);
118 // BENCHMARK_TEMPLATE(fill_n_1d, normal, static_tag, DStore);
119 BENCHMARK_TEMPLATE(fill_n_1d, uniform, dynamic_tag);
120 // BENCHMARK_TEMPLATE(fill_n_1d, uniform, dynamic_tag, DStore);
121 BENCHMARK_TEMPLATE(fill_n_1d, normal, dynamic_tag);
122 // BENCHMARK_TEMPLATE(fill_n_1d, normal, dynamic_tag, DStore);
123
124 BENCHMARK_TEMPLATE(fill_2d, uniform, static_tag);
125 // BENCHMARK_TEMPLATE(fill_2d, uniform, static_tag, DStore);
126 BENCHMARK_TEMPLATE(fill_2d, normal, static_tag);
127 // BENCHMARK_TEMPLATE(fill_2d, normal, static_tag, DStore);
128 BENCHMARK_TEMPLATE(fill_2d, uniform, dynamic_tag);
129 // BENCHMARK_TEMPLATE(fill_2d, uniform, dynamic_tag, DStore);
130 BENCHMARK_TEMPLATE(fill_2d, normal, dynamic_tag);
131 // BENCHMARK_TEMPLATE(fill_2d, normal, dynamic_tag, DStore);
132
133 BENCHMARK_TEMPLATE(fill_n_2d, uniform, static_tag);
134 // BENCHMARK_TEMPLATE(fill_n_2d, uniform, static_tag, DStore);
135 BENCHMARK_TEMPLATE(fill_n_2d, normal, static_tag);
136 // BENCHMARK_TEMPLATE(fill_n_2d, normal, static_tag, DStore);
137 BENCHMARK_TEMPLATE(fill_n_2d, uniform, dynamic_tag);
138 // BENCHMARK_TEMPLATE(fill_n_2d, uniform, dynamic_tag, DStore);
139 BENCHMARK_TEMPLATE(fill_n_2d, normal, dynamic_tag);
140 // BENCHMARK_TEMPLATE(fill_n_2d, normal, dynamic_tag, DStore);
141
142 BENCHMARK_TEMPLATE(fill_3d, uniform, static_tag);
143 // BENCHMARK_TEMPLATE(fill_3d, uniform, static_tag, DStore);
144 BENCHMARK_TEMPLATE(fill_3d, normal, static_tag);
145 // BENCHMARK_TEMPLATE(fill_3d, normal, static_tag, DStore);
146 BENCHMARK_TEMPLATE(fill_3d, uniform, dynamic_tag);
147 // BENCHMARK_TEMPLATE(fill_3d, uniform, dynamic_tag, DStore);
148 BENCHMARK_TEMPLATE(fill_3d, normal, dynamic_tag);
149 // BENCHMARK_TEMPLATE(fill_3d, normal, dynamic_tag, DStore);
150
151 BENCHMARK_TEMPLATE(fill_n_3d, uniform, static_tag);
152 // BENCHMARK_TEMPLATE(fill_n_3d, uniform, static_tag, DStore);
153 BENCHMARK_TEMPLATE(fill_n_3d, normal, static_tag);
154 // BENCHMARK_TEMPLATE(fill_n_3d, normal, static_tag, DStore);
155 BENCHMARK_TEMPLATE(fill_n_3d, uniform, dynamic_tag);
156 // BENCHMARK_TEMPLATE(fill_n_3d, uniform, dynamic_tag, DStore);
157 BENCHMARK_TEMPLATE(fill_n_3d, normal, dynamic_tag);
158 // BENCHMARK_TEMPLATE(fill_n_3d, normal, dynamic_tag, DStore);
159
160 BENCHMARK_TEMPLATE(fill_6d, uniform, static_tag);
161 // BENCHMARK_TEMPLATE(fill_6d, uniform, static_tag, DStore);
162 BENCHMARK_TEMPLATE(fill_6d, normal, static_tag);
163 // BENCHMARK_TEMPLATE(fill_6d, normal, static_tag, DStore);
164 BENCHMARK_TEMPLATE(fill_6d, uniform, dynamic_tag);
165 // BENCHMARK_TEMPLATE(fill_6d, uniform, dynamic_tag, DStore);
166 BENCHMARK_TEMPLATE(fill_6d, normal, dynamic_tag);
167 // BENCHMARK_TEMPLATE(fill_6d, normal, dynamic_tag, DStore);
168
169 BENCHMARK_TEMPLATE(fill_n_6d, uniform, static_tag);
170 // BENCHMARK_TEMPLATE(fill_n_6d, uniform, static_tag, DStore);
171 BENCHMARK_TEMPLATE(fill_n_6d, normal, static_tag);
172 // BENCHMARK_TEMPLATE(fill_n_6d, normal, static_tag, DStore);
173 BENCHMARK_TEMPLATE(fill_n_6d, uniform, dynamic_tag);
174 // BENCHMARK_TEMPLATE(fill_n_6d, uniform, dynamic_tag, DStore);
175 BENCHMARK_TEMPLATE(fill_n_6d, normal, dynamic_tag);
176 // BENCHMARK_TEMPLATE(fill_n_6d, normal, dynamic_tag, DStore);