Skip to content

Commit 3204de7

Browse files
committed
[hist] Add microbenchmarks for RAxes::ComputeGlobalIndex
This method will be extensively used during histogram filling, so it should be fast.
1 parent b2e001e commit 3204de7

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

hist/histv7/benchmark/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
add_executable(hist_benchmark_axes hist_benchmark_axes.cxx)
2+
target_link_libraries(hist_benchmark_axes ROOTHist benchmark::benchmark)
3+
14
add_executable(hist_benchmark_regular hist_benchmark_regular.cxx)
25
target_link_libraries(hist_benchmark_regular ROOTHist benchmark::benchmark)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <ROOT/RAxes.hxx>
2+
3+
#include <benchmark/benchmark.h>
4+
5+
#include <random>
6+
#include <tuple>
7+
#include <vector>
8+
9+
struct 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.
12+
ROOT::Experimental::RRegularAxis axis{20, 0.0, 1.0};
13+
ROOT::Experimental::Internal::RAxes axes{{axis}};
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+
29+
BENCHMARK_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+
}
37+
BENCHMARK_REGISTER_F(RAxes_Regular1, ComputeGlobalIndex)->Range(0, 32768);
38+
39+
struct 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.
42+
ROOT::Experimental::RRegularAxis axis{20, 0.0, 1.0};
43+
ROOT::Experimental::Internal::RAxes axes{{axis, axis}};
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+
59+
BENCHMARK_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+
}
67+
BENCHMARK_REGISTER_F(RAxes_Regular2, ComputeGlobalIndex)->Range(0, 32768);
68+
69+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)