Skip to content

Commit 509d9de

Browse files
committed
Add Ensure to RBConfig.h
...instead of having multiple implementations around the codebase.
1 parent 2e71873 commit 509d9de

File tree

5 files changed

+28
-48
lines changed

5 files changed

+28
-48
lines changed

include/rootbench/RBConfig.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ namespace RB {
3232
inline std::string GetDataDir() {
3333
return RB::kDatasetDirectory;
3434
}
35+
36+
/// Like assert, but it does not disappear if -DNDEBUG
37+
inline void Ensure(bool b)
38+
{
39+
if (!b)
40+
std::abort();
41+
}
3542
}
3643

3744
#endif

root/tree/dataframe/RDataFrameSumBenchmarks.cxx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ static constexpr auto nEntries = 100000;
2525
static const auto pathToFile = RB::GetTempFs() + "/" + fileName;
2626

2727

28-
inline void ensure(bool b)
29-
{
30-
if (!b)
31-
std::abort();
32-
}
33-
3428
void MakeDataIfNeeded()
3529
{
3630
const bool hasData = gSystem->AccessPathName(pathToFile.c_str()) == 0;
@@ -71,7 +65,7 @@ static void BM_RDataFrameSum_SumScalarDF(benchmark::State &state)
7165
int sum = 0;
7266
for (auto _ : state)
7367
sum = *df.Sum<int>(scalarBranch);
74-
ensure(sum == 42 * nEntries);
68+
RB::Ensure(sum == 42 * nEntries);
7569
}
7670
BENCHMARK(BM_RDataFrameSum_SumScalarDF);
7771

@@ -85,7 +79,7 @@ static void BM_RDataFrameSum_SumScalarWithForeach(benchmark::State &state)
8579
df.Foreach([&sum](int x) { sum += x; }, {scalarBranch});
8680
benchmark::DoNotOptimize(sum);
8781
}
88-
ensure(sum == 42 * nEntries);
82+
RB::Ensure(sum == 42 * nEntries);
8983
}
9084
BENCHMARK(BM_RDataFrameSum_SumScalarWithForeach);
9185

@@ -96,7 +90,7 @@ static void BM_RDataFrameSum_SumScalarAfter1Define(benchmark::State &state)
9690
int sum = 0;
9791
for (auto _ : state)
9892
sum = *df.Sum<int>("defined_var");
99-
ensure(sum == 42 * nEntries);
93+
RB::Ensure(sum == 42 * nEntries);
10094
}
10195
BENCHMARK(BM_RDataFrameSum_SumScalarAfter1Define);
10296

@@ -112,7 +106,7 @@ static void BM_RDataFrameSum_SumScalarAfter5Defines(benchmark::State &state)
112106
int sum = 0;
113107
for (auto _ : state)
114108
sum = *df.Sum<int>("def5");
115-
ensure(sum == 42 * nEntries);
109+
RB::Ensure(sum == 42 * nEntries);
116110
}
117111
BENCHMARK(BM_RDataFrameSum_SumScalarAfter5Defines);
118112

@@ -123,7 +117,7 @@ static void BM_RDataFrameSum_SumVectorDF(benchmark::State &state)
123117
int sum = 0;
124118
for (auto _ : state)
125119
sum = *df.Sum<RVec<int>>(vectorBranch);
126-
ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries);
120+
RB::Ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries);
127121
}
128122
BENCHMARK(BM_RDataFrameSum_SumVectorDF);
129123

@@ -135,7 +129,7 @@ static void BM_RDataFrameSum_SumVectorAfter1Define(benchmark::State &state)
135129
int sum = 0;
136130
for (auto _ : state)
137131
sum = *df.Sum<RVec<int>>("defined_var");
138-
ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries);
132+
RB::Ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries);
139133
}
140134
BENCHMARK(BM_RDataFrameSum_SumVectorAfter1Define);
141135

@@ -151,6 +145,6 @@ static void BM_RDataFrameSum_SumVectorAfter5Defines(benchmark::State &state)
151145
int sum = 0;
152146
for (auto _ : state)
153147
sum = *df.Sum<RVec<int>>("def5");
154-
ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries);
148+
RB::Ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries);
155149
}
156150
BENCHMARK(BM_RDataFrameSum_SumVectorAfter5Defines);

root/tree/tree/TTreeBenchmarks.cxx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ static constexpr auto nEntries = 8000;
1616
static auto pathOneBranch = RB::GetTempFs() + "/" + fileNameOneBranch;
1717
static auto pathTwoBranches = RB::GetTempFs() + "/" + fileNameTwoBranches;
1818

19-
// an assert implementation that is not no-op for optimized builds
20-
inline void ensure(bool b)
21-
{
22-
if (!b)
23-
std::abort();
24-
}
25-
2619
void MakeDataOneBranch()
2720
{
2821
const bool hasData = gSystem->AccessPathName(fileNameOneBranch) == 0;
@@ -72,7 +65,7 @@ static void BM_TTree_GetEntryReadOneOfOne(benchmark::State &state)
7265
}
7366
benchmark::DoNotOptimize(sum);
7467
}
75-
ensure(sum == 42 * nEntries_);
68+
RB::Ensure(sum == 42 * nEntries_);
7669
}
7770
BENCHMARK(BM_TTree_GetEntryReadOneOfOne);
7871

@@ -109,7 +102,7 @@ static void BM_TTree_GetEntryReadOneOfTwo(benchmark::State &state)
109102
}
110103
benchmark::DoNotOptimize(sum);
111104
}
112-
ensure(sum == 42 * nEntries_);
105+
RB::Ensure(sum == 42 * nEntries_);
113106
}
114107
BENCHMARK(BM_TTree_GetEntryReadOneOfTwo);
115108

@@ -130,7 +123,7 @@ static void BM_TTree_GetEntryReadTwoOfTwo(benchmark::State &state)
130123
}
131124
benchmark::DoNotOptimize(sum);
132125
}
133-
ensure(sum == 42 * nEntries_);
126+
RB::Ensure(sum == 42 * nEntries_);
134127
}
135128
BENCHMARK(BM_TTree_GetEntryReadTwoOfTwo);
136129

@@ -152,7 +145,7 @@ static void BM_TTree_BranchGetEntryReadOneOfOne(benchmark::State &state)
152145
}
153146
benchmark::DoNotOptimize(sum);
154147
}
155-
ensure(sum == 42 * nEntries_);
148+
RB::Ensure(sum == 42 * nEntries_);
156149
}
157150
BENCHMARK(BM_TTree_BranchGetEntryReadOneOfOne);
158151

@@ -174,7 +167,7 @@ static void BM_TTree_BranchGetEntryReadOneOfTwo(benchmark::State &state)
174167
}
175168
benchmark::DoNotOptimize(sum);
176169
}
177-
ensure(sum == 42 * nEntries_);
170+
RB::Ensure(sum == 42 * nEntries_);
178171
}
179172
BENCHMARK(BM_TTree_BranchGetEntryReadOneOfTwo);
180173

root/tree/tree/TTreeSumBenchmarks.cxx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515

1616
#include "rootbench/RBConfig.h"
1717

18-
inline void ensure(bool b)
19-
{
20-
if (!b)
21-
std::abort();
22-
}
23-
2418
using ROOT::RVec;
2519

2620
static constexpr auto treeName = "Events";
@@ -59,7 +53,7 @@ static void BM_TTreeSum_SumScalarTBranchGetEntry(benchmark::State &state)
5953
}
6054
benchmark::DoNotOptimize(sum);
6155
}
62-
ensure(sum == 42 * nEntries_);
56+
RB::Ensure(sum == 42 * nEntries_);
6357
}
6458
BENCHMARK(BM_TTreeSum_SumScalarTBranchGetEntry);
6559

@@ -82,7 +76,7 @@ static void BM_TTreeSum_SumScalarTTreeGetEntry(benchmark::State &state)
8276
}
8377
benchmark::DoNotOptimize(sum);
8478
}
85-
ensure(sum == 42 * nEntries_);
79+
RB::Ensure(sum == 42 * nEntries_);
8680
}
8781
BENCHMARK(BM_TTreeSum_SumScalarTTreeGetEntry);
8882

@@ -101,7 +95,7 @@ static void BM_TTreeSum_SumScalarTTreeReader(benchmark::State &state)
10195
sum += *x;
10296
benchmark::DoNotOptimize(sum);
10397
}
104-
ensure(sum == 42 * nEntries);
98+
RB::Ensure(sum == 42 * nEntries);
10599
}
106100
BENCHMARK(BM_TTreeSum_SumScalarTTreeReader);
107101

@@ -124,7 +118,7 @@ static void BM_TTreeSum_SumVectorTBranchGetEntry(benchmark::State &state)
124118
}
125119
benchmark::DoNotOptimize(sum);
126120
}
127-
ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries_);
121+
RB::Ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries_);
128122
}
129123
BENCHMARK(BM_TTreeSum_SumVectorTBranchGetEntry);
130124

@@ -144,6 +138,6 @@ static void BM_TTreeSum_SumVectorTTreeReader(benchmark::State &state)
144138
sum += e;
145139
benchmark::DoNotOptimize(sum);
146140
}
147-
ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries);
141+
RB::Ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries);
148142
}
149143
BENCHMARK(BM_TTreeSum_SumVectorTTreeReader);

root/tree/treeplayer/TTreePlayerBenchmarks.cxx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ static constexpr auto nEntries = 8000;
1818
static auto pathToFile = scratchDir + "/" + fileName;
1919

2020

21-
22-
// an assert implementation that is not no-op for optimized builds
23-
void ensure(bool b)
24-
{
25-
if (!b)
26-
std::abort();
27-
}
28-
2921
void MakeDataFixedArray()
3022
{
3123
TFile f(pathToFile.c_str(), "recreate");
@@ -81,7 +73,7 @@ static void BM_TTreePlayer_FixedSizeArrayTBranch(benchmark::State &state)
8173
}
8274
benchmark::DoNotOptimize(sum);
8375
}
84-
ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries_);
76+
RB::Ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries_);
8577
}
8678
BENCHMARK(BM_TTreePlayer_FixedSizeArrayTBranch);
8779

@@ -105,7 +97,7 @@ static void BM_TTreePlayer_VarSizeArrayTBranch(benchmark::State &state)
10597
}
10698
benchmark::DoNotOptimize(sum);
10799
}
108-
ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries_);
100+
RB::Ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries_);
109101
}
110102
BENCHMARK(BM_TTreePlayer_VarSizeArrayTBranch);
111103

@@ -128,7 +120,7 @@ static void BM_TTreePlayer_StdVectorTBranch(benchmark::State &state)
128120
}
129121
benchmark::DoNotOptimize(sum);
130122
}
131-
ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries_);
123+
RB::Ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries_);
132124
}
133125
BENCHMARK(BM_TTreePlayer_StdVectorTBranch);
134126

@@ -148,7 +140,7 @@ static void RunReaderArray(benchmark::State &state)
148140
}
149141
benchmark::DoNotOptimize(sum);
150142
}
151-
ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries);
143+
RB::Ensure(sum == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * nEntries);
152144
}
153145

154146
static void BM_TTreePlayer_FixedSizeArrayReaderArray(benchmark::State &state)

0 commit comments

Comments
 (0)