ROOT
master
Reference Guide
Loading...
Searching...
No Matches
hist_benchmark_atomic.cxx
Go to the documentation of this file.
1
#include <
ROOT/RBinWithError.hxx
>
2
#include <
ROOT/RHistUtils.hxx
>
3
4
// Note: In principle, the benchmark library supports multithreaded benchmarks. However, the output has historically
5
// been confusing (wrong): https://github.com/google/benchmark/issues/1834 This was changed / fixed in version 1.9.0:
6
// https://github.com/google/benchmark/pull/1836 Even then, the minimum benchmark time is not correctly respected (in
7
// the way I would expect): https://github.com/google/benchmark/issues/2117
8
// Moreover, measuring contention heavily depends on the machine, cache coherency, tread placement / binding, and other
9
// factors. Reproducibility is very hard to achieve with the limited control that the benchmark library offers.
10
// For these reasons, the following benchmarks are not automatically run with multiple threads to benchmark contention.
11
// Care should be taken when manually changing and trying to interpret the results!
12
// To keep this possiblity though, the benchmarks MUST NOT use benchmark::DoNotOptimize() on non-const references to
13
// shared variables: Older compilers (GCC before version 12.1.0) will load and store the value through the reference,
14
// which leads to data races!
15
#include <benchmark/benchmark.h>
16
17
#include <cstddef>
18
19
struct
RHistAtomic_int
:
public
benchmark::Fixture {
20
int
fAtomic
= 0;
21
};
22
23
BENCHMARK_DEFINE_F
(
RHistAtomic_int
,
Add
)(benchmark::State &state)
24
{
25
for
(
auto
_
: state) {
26
fAtomic += 1;
27
benchmark::ClobberMemory();
28
}
29
}
30
BENCHMARK_REGISTER_F
(
RHistAtomic_int
,
Add
);
31
32
BENCHMARK_DEFINE_F
(
RHistAtomic_int
, AtomicAdd)(benchmark::State &state)
33
{
34
for
(
auto
_
: state) {
35
ROOT::Experimental::Internal::AtomicAdd
(&fAtomic, 1);
36
benchmark::ClobberMemory();
37
}
38
}
39
BENCHMARK_REGISTER_F
(
RHistAtomic_int
, AtomicAdd);
40
41
struct
RHistAtomic_float
:
public
benchmark::Fixture {
42
float
fAtomic
= 0;
43
};
44
45
BENCHMARK_DEFINE_F
(
RHistAtomic_float
,
Add
)(benchmark::State &state)
46
{
47
for
(
auto
_
: state) {
48
fAtomic += 1.0f;
49
benchmark::ClobberMemory();
50
}
51
}
52
BENCHMARK_REGISTER_F
(
RHistAtomic_float
,
Add
);
53
54
BENCHMARK_DEFINE_F
(
RHistAtomic_float
, AtomicAdd)(benchmark::State &state)
55
{
56
for
(
auto
_
: state) {
57
ROOT::Experimental::Internal::AtomicAdd
(&fAtomic, 1.0f);
58
benchmark::ClobberMemory();
59
}
60
}
61
BENCHMARK_REGISTER_F
(
RHistAtomic_float
, AtomicAdd);
62
63
struct
RHistAtomic_double
:
public
benchmark::Fixture {
64
double
fAtomic
= 0;
65
};
66
67
BENCHMARK_DEFINE_F
(
RHistAtomic_double
,
Add
)(benchmark::State &state)
68
{
69
for
(
auto
_
: state) {
70
fAtomic += 1.0;
71
benchmark::ClobberMemory();
72
}
73
}
74
BENCHMARK_REGISTER_F
(
RHistAtomic_double
,
Add
);
75
76
BENCHMARK_DEFINE_F
(
RHistAtomic_double
, AtomicAdd)(benchmark::State &state)
77
{
78
for
(
auto
_
: state) {
79
ROOT::Experimental::Internal::AtomicAdd
(&fAtomic, 1.0);
80
benchmark::ClobberMemory();
81
}
82
}
83
BENCHMARK_REGISTER_F
(
RHistAtomic_double
, AtomicAdd);
84
85
struct
RBinWithError
:
public
benchmark::Fixture {
86
ROOT::Experimental::RBinWithError
fBin
;
87
};
88
89
BENCHMARK_DEFINE_F
(
RBinWithError
, Inc)(benchmark::State &state)
90
{
91
for
(
auto
_
: state) {
92
fBin++;
93
benchmark::ClobberMemory();
94
}
95
}
96
BENCHMARK_REGISTER_F
(
RBinWithError
, Inc);
97
98
BENCHMARK_DEFINE_F
(
RBinWithError
, AtomicInc)(benchmark::State &state)
99
{
100
for
(
auto
_
: state) {
101
fBin.AtomicInc();
102
benchmark::ClobberMemory();
103
}
104
}
105
BENCHMARK_REGISTER_F
(
RBinWithError
, AtomicInc);
106
107
BENCHMARK_DEFINE_F
(
RBinWithError
,
Add
)(benchmark::State &state)
108
{
109
for
(
auto
_
: state) {
110
fBin += 1.0;
111
benchmark::ClobberMemory();
112
}
113
}
114
BENCHMARK_REGISTER_F
(
RBinWithError
,
Add
);
115
116
BENCHMARK_DEFINE_F
(
RBinWithError
, AtomicAdd)(benchmark::State &state)
117
{
118
for
(
auto
_
: state) {
119
fBin.AtomicAdd(1.0);
120
benchmark::ClobberMemory();
121
}
122
}
123
BENCHMARK_REGISTER_F
(
RBinWithError
, AtomicAdd);
124
125
BENCHMARK_MAIN
();
RBinWithError.hxx
RHistUtils.hxx
_
#define _(A, B)
Definition
cfortran.h:108
BENCHMARK_DEFINE_F
BENCHMARK_DEFINE_F(RHistAtomic_int, Add)(benchmark
Definition
hist_benchmark_atomic.cxx:23
BENCHMARK_MAIN
BENCHMARK_MAIN()
BENCHMARK_REGISTER_F
BENCHMARK_REGISTER_F(RHistAtomic_int, Add)
ROOT::Experimental::Internal::AtomicAdd
std::enable_if_t< std::is_integral_v< T > > AtomicAdd(T *ptr, T val)
Definition
RHistUtils.hxx:213
TMatrixTAutoloadOps::Add
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.
Definition
TMatrixT.cxx:2935
RBinWithError
Definition
hist_benchmark_atomic.cxx:85
RBinWithError::fBin
ROOT::Experimental::RBinWithError fBin
Definition
hist_benchmark_atomic.cxx:86
RHistAtomic_double
Definition
hist_benchmark_atomic.cxx:63
RHistAtomic_double::fAtomic
double fAtomic
Definition
hist_benchmark_atomic.cxx:64
RHistAtomic_float
Definition
hist_benchmark_atomic.cxx:41
RHistAtomic_float::fAtomic
float fAtomic
Definition
hist_benchmark_atomic.cxx:42
RHistAtomic_int
Definition
hist_benchmark_atomic.cxx:19
RHistAtomic_int::fAtomic
int fAtomic
Definition
hist_benchmark_atomic.cxx:20
ROOT::Experimental::RBinWithError
A special bin content type to compute the bin error in weighted filling.
Definition
RBinWithError.hxx:21
hist
histv7
benchmark
hist_benchmark_atomic.cxx
ROOTmaster - Reference Guide Generated on Wed Feb 11 2026 03:38:05 (GVA Time) using Doxygen 1.10.0