Skip to content

Commit

Permalink
Use results in concurrent hash map bench
Browse files Browse the repository at this point in the history
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.

X-link: facebook/folly#2393

Reviewed By: yfeldblum

Differential Revision: D70711095

Pulled By: YifanYuan3

fbshipit-source-id: 97440b5f823ff732efd5763545c2fd603a714b1c
  • Loading branch information
krenzland authored and facebook-github-bot committed Mar 7, 2025
1 parent e58bd18 commit 36295b2
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <iostream>
#include <thread>

#include <folly/BenchmarkUtil.h>
#include <folly/portability/GFlags.h>
#include <folly/synchronization/test/Barrier.h>

Expand Down Expand Up @@ -93,7 +94,7 @@ uint64_t bench_ctor_dtor(
for (int i = 0; i < ops; ++i) {
folly::ConcurrentHashMap<int, int> m;
for (int j = 0; j < size; ++j) {
m.insert(j, j);
folly::doNotOptimizeAway(m.insert(j, j));
}
}
};
Expand All @@ -115,11 +116,11 @@ uint64_t bench_find(
auto fn = [&](int) {
if (sameItem) {
for (int i = 0; i < ops; ++i) {
m.find(key);
folly::doNotOptimizeAway(m.find(key));
}
} else {
for (int i = 0; i < ops; ++i) {
m.find(i);
folly::doNotOptimizeAway(m.find(i));
}
}
};
Expand All @@ -139,7 +140,7 @@ uint64_t bench_iter(const int nthr, int size, const std::string& name) {
auto repFn = [&] {
auto fn = [&](int) {
for (int i = 0; i < reps; ++i) {
for (auto it = m.begin(); it != m.end(); ++it) {
for (auto it = m.begin(); it != m.end(); doNotOptimizeAway(++it)) {
}
}
};
Expand All @@ -158,7 +159,7 @@ uint64_t bench_begin(const int nthr, int size, const std::string& name) {
auto repFn = [&] {
auto fn = [&](int) {
for (int i = 0; i < ops; ++i) {
auto it = m.begin();
folly::doNotOptimizeAway(m.begin());
}
};
auto endfn = [&] {};
Expand All @@ -176,7 +177,7 @@ uint64_t bench_empty(const int nthr, int size, const std::string& name) {
auto repFn = [&] {
auto fn = [&](int) {
for (int i = 0; i < ops; ++i) {
m.empty();
folly::doNotOptimizeAway(m.empty());
}
};
auto endfn = [&] {};
Expand All @@ -194,7 +195,7 @@ uint64_t bench_size(const int nthr, int size, const std::string& name) {
auto repFn = [&] {
auto fn = [&](int) {
for (int i = 0; i < ops; ++i) {
m.size();
folly::doNotOptimizeAway(m.size());
}
};
auto endfn = [&] {};
Expand Down

0 comments on commit 36295b2

Please sign in to comment.