Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hist/histv7/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ target_link_libraries(hist_benchmark_engine ROOTHist benchmark::benchmark)

add_executable(hist_benchmark_regular hist_benchmark_regular.cxx)
target_link_libraries(hist_benchmark_regular ROOTHist benchmark::benchmark)

add_executable(hist_benchmark_stats hist_benchmark_stats.cxx)
target_link_libraries(hist_benchmark_stats ROOTHist benchmark::benchmark)
87 changes: 87 additions & 0 deletions hist/histv7/benchmark/hist_benchmark_stats.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <ROOT/RHistStats.hxx>
#include <ROOT/RWeight.hxx>

#include <benchmark/benchmark.h>

#include <random>
#include <vector>

struct RHistStats1 : public benchmark::Fixture {
// The object is stored and constructed in the fixture to avoid compiler optimizations in the benchmark body taking
// advantage of the (constant) constructor parameters.
ROOT::Experimental::RHistStats stats{1};
std::vector<double> fNumbers;

// Avoid GCC warning
using benchmark::Fixture::SetUp;
void SetUp(benchmark::State &state) final
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(state.range(0));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
}
};

BENCHMARK_DEFINE_F(RHistStats1, Fill)(benchmark::State &state)
{
for (auto _ : state) {
for (double number : fNumbers) {
stats.Fill(number);
}
}
}
BENCHMARK_REGISTER_F(RHistStats1, Fill)->Range(0, 32768);

BENCHMARK_DEFINE_F(RHistStats1, FillWeight)(benchmark::State &state)
{
for (auto _ : state) {
for (double number : fNumbers) {
stats.Fill(number, ROOT::Experimental::RWeight(0.8));
}
}
}
BENCHMARK_REGISTER_F(RHistStats1, FillWeight)->Range(0, 32768);

struct RHistStats2 : public benchmark::Fixture {
// The object is stored and constructed in the fixture to avoid compiler optimizations in the benchmark body taking
// advantage of the (constant) constructor parameters.
ROOT::Experimental::RHistStats stats{2};
std::vector<double> fNumbers;

// Avoid GCC warning
using benchmark::Fixture::SetUp;
void SetUp(benchmark::State &state) final
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(2 * state.range(0));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
}
};

BENCHMARK_DEFINE_F(RHistStats2, Fill)(benchmark::State &state)
{
for (auto _ : state) {
for (std::size_t i = 0; i < fNumbers.size(); i += 2) {
stats.Fill(fNumbers[i], fNumbers[i + 1]);
}
}
}
BENCHMARK_REGISTER_F(RHistStats2, Fill)->Range(0, 32768);

BENCHMARK_DEFINE_F(RHistStats2, FillWeight)(benchmark::State &state)
{
for (auto _ : state) {
for (std::size_t i = 0; i < fNumbers.size(); i += 2) {
stats.Fill(fNumbers[i], fNumbers[i + 1], ROOT::Experimental::RWeight(0.8));
}
}
}
BENCHMARK_REGISTER_F(RHistStats2, FillWeight)->Range(0, 32768);

BENCHMARK_MAIN();
1 change: 1 addition & 0 deletions hist/histv7/headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(histv7_headers
ROOT/RBinIndexRange.hxx
ROOT/RBinWithError.hxx
ROOT/RHistEngine.hxx
ROOT/RHistStats.hxx
ROOT/RHistUtils.hxx
ROOT/RLinearizedIndex.hxx
ROOT/RRegularAxis.hxx
Expand Down
1 change: 1 addition & 0 deletions hist/histv7/inc/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma link C++ class ROOT::Experimental::RHistEngine<float>-;
#pragma link C++ class ROOT::Experimental::RHistEngine<double>-;

#pragma link C++ class ROOT::Experimental::RHistStats-;
#pragma link C++ class ROOT::Experimental::RRegularAxis-;
#pragma link C++ class ROOT::Experimental::RVariableBinAxis-;
#pragma link C++ class ROOT::Experimental::Internal::RAxes-;
Loading
Loading