]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/histogram/benchmark/histogram_filling_root.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / histogram / benchmark / histogram_filling_root.cpp
CommitLineData
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
15struct assert_check {
16 assert_check() {
20effc67 17 assert(false); // don't run with asserts enabled
92f5a8d4
TL
18 }
19} _;
20
21template <class Distribution>
22static 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
29template <class Distribution>
30static 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
37template <class Distribution>
38static 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
45template <class Distribution>
46static 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
59BENCHMARK_TEMPLATE(fill_1d, uniform);
60BENCHMARK_TEMPLATE(fill_2d, uniform);
61BENCHMARK_TEMPLATE(fill_3d, uniform);
62BENCHMARK_TEMPLATE(fill_6d, uniform);
63
64BENCHMARK_TEMPLATE(fill_1d, normal);
65BENCHMARK_TEMPLATE(fill_2d, normal);
66BENCHMARK_TEMPLATE(fill_3d, normal);
67BENCHMARK_TEMPLATE(fill_6d, normal);