Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist_benchmark_axes.cxx
Go to the documentation of this file.
1#include <ROOT/RAxes.hxx>
2
3#include <benchmark/benchmark.h>
4
5#include <cstddef>
6#include <random>
7#include <tuple>
8#include <vector>
9
10struct RAxes_Regular1 : public benchmark::Fixture {
11 // The objects are stored and constructed in the fixture to avoid compiler optimizations in the benchmark body taking
12 // advantage of the (constant) constructor parameters.
15 std::vector<double> fNumbers;
16
17 // Avoid GCC warning
18 using benchmark::Fixture::SetUp;
19 void SetUp(benchmark::State &state) final
20 {
21 std::mt19937 gen;
22 std::uniform_real_distribution<> dis;
23 fNumbers.resize(static_cast<std::size_t>(state.range(0)));
24 for (std::size_t i = 0; i < fNumbers.size(); i++) {
25 fNumbers[i] = dis(gen);
26 }
27 }
28};
29
30BENCHMARK_DEFINE_F(RAxes_Regular1, ComputeGlobalIndex)(benchmark::State &state)
31{
32 for (auto _ : state) {
33 for (double number : fNumbers) {
34 benchmark::DoNotOptimize(axes.ComputeGlobalIndex(std::make_tuple(number)));
35 }
36 }
37}
38BENCHMARK_REGISTER_F(RAxes_Regular1, ComputeGlobalIndex)->Range(0, 32768);
39
40struct RAxes_Regular2 : public benchmark::Fixture {
41 // The objects are stored and constructed in the fixture to avoid compiler optimizations in the benchmark body taking
42 // advantage of the (constant) constructor parameters.
45 std::vector<double> fNumbers;
46
47 // Avoid GCC warning
48 using benchmark::Fixture::SetUp;
49 void SetUp(benchmark::State &state) final
50 {
51 std::mt19937 gen;
52 std::uniform_real_distribution<> dis;
53 fNumbers.resize(2 * static_cast<std::size_t>(state.range(0)));
54 for (std::size_t i = 0; i < fNumbers.size(); i++) {
55 fNumbers[i] = dis(gen);
56 }
57 }
58};
59
60BENCHMARK_DEFINE_F(RAxes_Regular2, ComputeGlobalIndex)(benchmark::State &state)
61{
62 for (auto _ : state) {
63 for (std::size_t i = 0; i < fNumbers.size(); i += 2) {
64 benchmark::DoNotOptimize(axes.ComputeGlobalIndex(std::make_tuple(fNumbers[i], fNumbers[i + 1])));
65 }
66 }
67}
68BENCHMARK_REGISTER_F(RAxes_Regular2, ComputeGlobalIndex)->Range(0, 32768);
69
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define _(A, B)
Definition cfortran.h:108
Bin configurations for all dimensions of a histogram.
Definition RAxes.hxx:39
A regular axis with equidistant bins in the interval .
BENCHMARK_MAIN()
BENCHMARK_DEFINE_F(RAxes_Regular1, ComputeGlobalIndex)(benchmark
BENCHMARK_REGISTER_F(RAxes_Regular1, ComputeGlobalIndex) -> Range(0, 32768)
ROOT::Experimental::Internal::RAxes axes
ROOT::Experimental::RRegularAxis axis
void SetUp(benchmark::State &state) final
std::vector< double > fNumbers
void SetUp(benchmark::State &state) final
ROOT::Experimental::RRegularAxis axis
std::vector< double > fNumbers
ROOT::Experimental::Internal::RAxes axes