From 36295b2c3eda7239fa09ef721fbc1d707bb784a0 Mon Sep 17 00:00:00 2001 From: Lukas Krenz Date: Fri, 7 Mar 2025 12:57:50 -0800 Subject: [PATCH] Use results in concurrent hash map bench 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: https://github.com/facebook/folly/pull/2393 Reviewed By: yfeldblum Differential Revision: D70711095 Pulled By: YifanYuan3 fbshipit-source-id: 97440b5f823ff732efd5763545c2fd603a714b1c --- .../concurrency/test/ConcurrentHashMapBench.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/third-party/folly/src/folly/concurrency/test/ConcurrentHashMapBench.cpp b/third-party/folly/src/folly/concurrency/test/ConcurrentHashMapBench.cpp index ba76860360fb5..770c47ed0520d 100644 --- a/third-party/folly/src/folly/concurrency/test/ConcurrentHashMapBench.cpp +++ b/third-party/folly/src/folly/concurrency/test/ConcurrentHashMapBench.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -93,7 +94,7 @@ uint64_t bench_ctor_dtor( for (int i = 0; i < ops; ++i) { folly::ConcurrentHashMap m; for (int j = 0; j < size; ++j) { - m.insert(j, j); + folly::doNotOptimizeAway(m.insert(j, j)); } } }; @@ -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)); } } }; @@ -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)) { } } }; @@ -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 = [&] {}; @@ -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 = [&] {}; @@ -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 = [&] {};