Skip to content

Commit 1b27a58

Browse files
krenzlandfacebook-github-bot
authored andcommittedMar 7, 2025·
Use results in concurrent hash map bench (#2393)
Summary: This PR adds `folly::doNotOptimizeAway` to all concurrent hash map benchmarks. Without this, gcc and clang (with larger inlining threshold) may remove parts of the benchmark. Pull Request resolved: #2393 Reviewed By: yfeldblum Differential Revision: D70711095 Pulled By: YifanYuan3 fbshipit-source-id: 97440b5f823ff732efd5763545c2fd603a714b1c
1 parent c452e63 commit 1b27a58

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
 

‎folly/concurrency/test/ConcurrentHashMapBench.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <iostream>
2121
#include <thread>
2222

23+
#include <folly/BenchmarkUtil.h>
2324
#include <folly/portability/GFlags.h>
2425
#include <folly/synchronization/test/Barrier.h>
2526

@@ -93,7 +94,7 @@ uint64_t bench_ctor_dtor(
9394
for (int i = 0; i < ops; ++i) {
9495
folly::ConcurrentHashMap<int, int> m;
9596
for (int j = 0; j < size; ++j) {
96-
m.insert(j, j);
97+
folly::doNotOptimizeAway(m.insert(j, j));
9798
}
9899
}
99100
};
@@ -115,11 +116,11 @@ uint64_t bench_find(
115116
auto fn = [&](int) {
116117
if (sameItem) {
117118
for (int i = 0; i < ops; ++i) {
118-
m.find(key);
119+
folly::doNotOptimizeAway(m.find(key));
119120
}
120121
} else {
121122
for (int i = 0; i < ops; ++i) {
122-
m.find(i);
123+
folly::doNotOptimizeAway(m.find(i));
123124
}
124125
}
125126
};
@@ -139,7 +140,7 @@ uint64_t bench_iter(const int nthr, int size, const std::string& name) {
139140
auto repFn = [&] {
140141
auto fn = [&](int) {
141142
for (int i = 0; i < reps; ++i) {
142-
for (auto it = m.begin(); it != m.end(); ++it) {
143+
for (auto it = m.begin(); it != m.end(); doNotOptimizeAway(++it)) {
143144
}
144145
}
145146
};
@@ -158,7 +159,7 @@ uint64_t bench_begin(const int nthr, int size, const std::string& name) {
158159
auto repFn = [&] {
159160
auto fn = [&](int) {
160161
for (int i = 0; i < ops; ++i) {
161-
auto it = m.begin();
162+
folly::doNotOptimizeAway(m.begin());
162163
}
163164
};
164165
auto endfn = [&] {};
@@ -176,7 +177,7 @@ uint64_t bench_empty(const int nthr, int size, const std::string& name) {
176177
auto repFn = [&] {
177178
auto fn = [&](int) {
178179
for (int i = 0; i < ops; ++i) {
179-
m.empty();
180+
folly::doNotOptimizeAway(m.empty());
180181
}
181182
};
182183
auto endfn = [&] {};
@@ -194,7 +195,7 @@ uint64_t bench_size(const int nthr, int size, const std::string& name) {
194195
auto repFn = [&] {
195196
auto fn = [&](int) {
196197
for (int i = 0; i < ops; ++i) {
197-
m.size();
198+
folly::doNotOptimizeAway(m.size());
198199
}
199200
};
200201
auto endfn = [&] {};

0 commit comments

Comments
 (0)
Please sign in to comment.