]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
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 <TH1I.h> | |
8 | #include <TH2I.h> | |
9 | #include <TH3I.h> | |
10 | #include <THn.h> | |
11 | #include <benchmark/benchmark.h> | |
12 | #include "generator.hpp" | |
13 | ||
20effc67 | 14 | #include <cassert> |
92f5a8d4 TL |
15 | struct assert_check { |
16 | assert_check() { | |
20effc67 | 17 | assert(false); // don't run with asserts enabled |
92f5a8d4 TL |
18 | } |
19 | } _; | |
20 | ||
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()); | |
27 | } | |
28 | ||
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); | |
35 | } | |
36 | ||
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); | |
43 | } | |
44 | ||
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)); | |
55 | } | |
56 | state.SetItemsProcessed(state.iterations() * 6); | |
57 | } | |
58 | ||
59 | BENCHMARK_TEMPLATE(fill_1d, uniform); | |
60 | BENCHMARK_TEMPLATE(fill_2d, uniform); | |
61 | BENCHMARK_TEMPLATE(fill_3d, uniform); | |
62 | BENCHMARK_TEMPLATE(fill_6d, uniform); | |
63 | ||
64 | BENCHMARK_TEMPLATE(fill_1d, normal); | |
65 | BENCHMARK_TEMPLATE(fill_2d, normal); | |
66 | BENCHMARK_TEMPLATE(fill_3d, normal); | |
67 | BENCHMARK_TEMPLATE(fill_6d, normal); |