[libcxx-commits] [libcxx] [libc++] Make the associative container query benchmarks more representative (PR #183036)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Mar 13 05:59:23 PDT 2026
================
@@ -687,74 +687,32 @@ void associative_container_benchmarks(std::string container) {
/////////////////////////
// Query
/////////////////////////
- auto with_existent_key = [=](auto func) {
+ auto query_bench = [=](auto func) {
return [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size));
- // Pick any `BatchSize` number of elements
- std::vector<Key> keys;
- for (std::size_t i = 0; i < in.size(); i += (in.size() / BatchSize)) {
- keys.push_back(get_key(in.at(i)));
- }
Container c(in.begin(), in.end());
- while (st.KeepRunningBatch(BatchSize)) {
- for (std::size_t i = 0; i != keys.size(); ++i) { // possible empty keys when Arg(0)
- auto result = func(c, keys[i]);
- benchmark::DoNotOptimize(c);
- benchmark::DoNotOptimize(result);
- benchmark::ClobberMemory();
- }
- }
- };
- };
-
- auto with_nonexistent_key = [=](auto func) {
----------------
philnik777 wrote:
All the numbers are pretty much within the noise, so I don't think we need to benchmark both cases:
```
Benchmark 89d2d7aa87e2 455d0f85674f Difference % Difference
--------------------------------------------------------------------------------------- -------------- -------------- ------------ --------------
std::set<int>::contains(key)/1024 33.20 32.27 -0.93 -2.79%
std::set<int>::contains(key)/32 17.80 17.97 0.17 0.96%
std::set<int>::contains(key)/8192 73.19 71.19 -2.00 -2.73%
std::set<int>::count(key)/1024 34.85 34.10 -0.75 -2.16%
std::set<int>::count(key)/32 17.74 17.85 0.11 0.60%
std::set<int>::count(key)/8192 74.14 74.28 0.14 0.19%
std::set<int>::equal_range(key)/1024 34.85 36.14 1.28 3.68%
std::set<int>::equal_range(key)/32 17.65 17.80 0.15 0.85%
std::set<int>::equal_range(key)/8192 74.05 74.17 0.11 0.15%
std::set<int>::find(key)/1024 32.37 32.53 0.16 0.49%
std::set<int>::find(key)/32 17.44 17.66 0.22 1.29%
std::set<int>::find(key)/8192 73.67 72.33 -1.33 -1.81%
std::set<int>::lower_bound(key)/1024 34.20 35.61 1.41 4.13%
std::set<int>::lower_bound(key)/32 17.72 17.98 0.26 1.49%
std::set<int>::lower_bound(key)/8192 74.53 74.47 -0.06 -0.08%
std::set<int>::upper_bound(key)/1024 37.80 34.29 -3.51 -9.28%
std::set<int>::upper_bound(key)/32 17.60 17.76 0.17 0.96%
std::set<int>::upper_bound(key)/8192 73.80 73.08 -0.72 -0.97%
std::set<std::string>::contains(key)/1024 91.42 92.86 1.44 1.58%
std::set<std::string>::contains(key)/32 54.18 54.23 0.05 0.09%
std::set<std::string>::contains(key)/8192 181.43 178.76 -2.68 -1.47%
std::set<std::string>::count(key)/1024 90.76 90.66 -0.10 -0.11%
std::set<std::string>::count(key)/32 52.27 54.12 1.85 3.54%
std::set<std::string>::count(key)/8192 173.10 175.53 2.43 1.40%
std::set<std::string>::equal_range(key)/1024 90.92 92.08 1.15 1.27%
std::set<std::string>::equal_range(key)/32 52.84 56.26 3.42 6.48%
std::set<std::string>::equal_range(key)/8192 182.72 181.55 -1.17 -0.64%
std::set<std::string>::find(key)/1024 108.65 103.02 -5.63 -5.19%
std::set<std::string>::find(key)/32 54.88 53.54 -1.34 -2.45%
std::set<std::string>::find(key)/8192 187.35 187.91 0.56 0.30%
std::set<std::string>::lower_bound(key)/1024 92.67 91.38 -1.29 -1.39%
std::set<std::string>::lower_bound(key)/32 55.06 51.74 -3.31 -6.01%
std::set<std::string>::lower_bound(key)/8192 180.07 181.87 1.79 1.00%
std::set<std::string>::upper_bound(key)/1024 89.04 91.43 2.38 2.67%
std::set<std::string>::upper_bound(key)/32 52.34 54.97 2.63 5.02%
std::set<std::string>::upper_bound(key)/8192 181.55 181.49 -0.06 -0.03%
```
https://github.com/llvm/llvm-project/pull/183036
More information about the libcxx-commits
mailing list