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 <random>
6#include <tuple>
7#include <vector>
8
9struct RAxes_Regular1 : public benchmark::Fixture {
10 // The objects are stored and constructed in the fixture to avoid compiler optimizations in the benchmark body taking
11 // advantage of the (constant) constructor parameters.
14 std::vector<double> fNumbers;
15
16 // Avoid GCC warning
17 using benchmark::Fixture::SetUp;
18 void SetUp(benchmark::State &state) final
19 {
20 std::mt19937 gen;
21 std::uniform_real_distribution<> dis;
22 fNumbers.resize(state.range(0));
23 for (std::size_t i = 0; i < fNumbers.size(); i++) {
24 fNumbers[i] = dis(gen);
25 }
26 }
27};
28
29BENCHMARK_DEFINE_F(RAxes_Regular1, ComputeGlobalIndex)(benchmark::State &state)
30{
31 for (auto _ : state) {
32 for (double number : fNumbers) {
33 benchmark::DoNotOptimize(axes.ComputeGlobalIndex(std::make_tuple(number)));
34 }
35 }
36}
37BENCHMARK_REGISTER_F(RAxes_Regular1, ComputeGlobalIndex)->Range(0, 32768);
38
39struct RAxes_Regular2 : public benchmark::Fixture {
40 // The objects are stored and constructed in the fixture to avoid compiler optimizations in the benchmark body taking
41 // advantage of the (constant) constructor parameters.
44 std::vector<double> fNumbers;
45
46 // Avoid GCC warning
47 using benchmark::Fixture::SetUp;
48 void SetUp(benchmark::State &state) final
49 {
50 std::mt19937 gen;
51 std::uniform_real_distribution<> dis;
52 fNumbers.resize(2 * state.range(0));
53 for (std::size_t i = 0; i < fNumbers.size(); i++) {
54 fNumbers[i] = dis(gen);
55 }
56 }
57};
58
59BENCHMARK_DEFINE_F(RAxes_Regular2, ComputeGlobalIndex)(benchmark::State &state)
60{
61 for (auto _ : state) {
62 for (std::size_t i = 0; i < fNumbers.size(); i += 2) {
63 benchmark::DoNotOptimize(axes.ComputeGlobalIndex(std::make_tuple(fNumbers[i], fNumbers[i + 1])));
64 }
65 }
66}
67BENCHMARK_REGISTER_F(RAxes_Regular2, ComputeGlobalIndex)->Range(0, 32768);
68
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:34
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