Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist_benchmark_atomic.cxx
Go to the documentation of this file.
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
19struct RHistAtomic_int : public benchmark::Fixture {
20 int fAtomic = 0;
21};
22
23BENCHMARK_DEFINE_F(RHistAtomic_int, Add)(benchmark::State &state)
24{
25 for (auto _ : state) {
26 fAtomic += 1;
27 benchmark::ClobberMemory();
28 }
29}
31
32BENCHMARK_DEFINE_F(RHistAtomic_int, AtomicAdd)(benchmark::State &state)
33{
34 for (auto _ : state) {
36 benchmark::ClobberMemory();
37 }
38}
40
41struct RHistAtomic_float : public benchmark::Fixture {
42 float fAtomic = 0;
43};
44
45BENCHMARK_DEFINE_F(RHistAtomic_float, Add)(benchmark::State &state)
46{
47 for (auto _ : state) {
48 fAtomic += 1.0f;
49 benchmark::ClobberMemory();
50 }
51}
53
54BENCHMARK_DEFINE_F(RHistAtomic_float, AtomicAdd)(benchmark::State &state)
55{
56 for (auto _ : state) {
58 benchmark::ClobberMemory();
59 }
60}
62
63struct RHistAtomic_double : public benchmark::Fixture {
64 double fAtomic = 0;
65};
66
67BENCHMARK_DEFINE_F(RHistAtomic_double, Add)(benchmark::State &state)
68{
69 for (auto _ : state) {
70 fAtomic += 1.0;
71 benchmark::ClobberMemory();
72 }
73}
75
76BENCHMARK_DEFINE_F(RHistAtomic_double, AtomicAdd)(benchmark::State &state)
77{
78 for (auto _ : state) {
80 benchmark::ClobberMemory();
81 }
82}
84
85struct RBinWithError : public benchmark::Fixture {
87};
88
89BENCHMARK_DEFINE_F(RBinWithError, Inc)(benchmark::State &state)
90{
91 for (auto _ : state) {
92 fBin++;
93 benchmark::ClobberMemory();
94 }
95}
97
98BENCHMARK_DEFINE_F(RBinWithError, AtomicInc)(benchmark::State &state)
99{
100 for (auto _ : state) {
101 fBin.AtomicInc();
102 benchmark::ClobberMemory();
103 }
104}
106
107BENCHMARK_DEFINE_F(RBinWithError, Add)(benchmark::State &state)
108{
109 for (auto _ : state) {
110 fBin += 1.0;
111 benchmark::ClobberMemory();
112 }
113}
115
116BENCHMARK_DEFINE_F(RBinWithError, AtomicAdd)(benchmark::State &state)
117{
118 for (auto _ : state) {
119 fBin.AtomicAdd(1.0);
120 benchmark::ClobberMemory();
121 }
122}
124
#define _(A, B)
Definition cfortran.h:108
BENCHMARK_DEFINE_F(RHistAtomic_int, Add)(benchmark
BENCHMARK_MAIN()
BENCHMARK_REGISTER_F(RHistAtomic_int, Add)
std::enable_if_t< std::is_integral_v< T > > AtomicAdd(T *ptr, T val)
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.
ROOT::Experimental::RBinWithError fBin
A special bin content type to compute the bin error in weighted filling.