]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/benchmark/histogram_filling_root.cpp
1 // Copyright 2015-2019 Hans Dembinski
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)
11 #include <benchmark/benchmark.h>
12 #include "generator.hpp"
17 assert(false); // don't run with asserts enabled
21 template <class Distribution
>
22 static void fill_1d(benchmark::State
& state
) {
23 TH1I
h("", "", 100, 0, 1);
24 generator
<Distribution
> gen
;
25 for (auto _
: state
) benchmark::DoNotOptimize(h
.Fill(gen()));
26 state
.SetItemsProcessed(state
.iterations());
29 template <class Distribution
>
30 static void fill_2d(benchmark::State
& state
) {
31 TH2I
h("", "", 100, 0, 1, 100, 0, 1);
32 generator
<Distribution
> gen
;
33 for (auto _
: state
) benchmark::DoNotOptimize(h
.Fill(gen(), gen()));
34 state
.SetItemsProcessed(state
.iterations() * 2);
37 template <class Distribution
>
38 static void fill_3d(benchmark::State
& state
) {
39 TH3I
h("", "", 100, 0, 1, 100, 0, 1, 100, 0, 1);
40 generator
<Distribution
> gen
;
41 for (auto _
: state
) benchmark::DoNotOptimize(h
.Fill(gen(), gen(), gen()));
42 state
.SetItemsProcessed(state
.iterations() * 3);
45 template <class Distribution
>
46 static void fill_6d(benchmark::State
& state
) {
47 int bin
[] = {10, 10, 10, 10, 10, 10};
48 double min
[] = {0, 0, 0, 0, 0, 0};
49 double max
[] = {1, 1, 1, 1, 1, 1};
50 THnI
h("", "", 6, bin
, min
, max
);
51 generator
<Distribution
> gen
;
52 for (auto _
: state
) {
53 const double buf
[6] = {gen(), gen(), gen(), gen(), gen(), gen()};
54 benchmark::DoNotOptimize(h
.Fill(buf
));
56 state
.SetItemsProcessed(state
.iterations() * 6);
59 BENCHMARK_TEMPLATE(fill_1d
, uniform
);
60 BENCHMARK_TEMPLATE(fill_2d
, uniform
);
61 BENCHMARK_TEMPLATE(fill_3d
, uniform
);
62 BENCHMARK_TEMPLATE(fill_6d
, uniform
);
64 BENCHMARK_TEMPLATE(fill_1d
, normal
);
65 BENCHMARK_TEMPLATE(fill_2d
, normal
);
66 BENCHMARK_TEMPLATE(fill_3d
, normal
);
67 BENCHMARK_TEMPLATE(fill_6d
, normal
);