[libcxx-commits] [libcxx] [libc++] Make the associative container query benchmarks more representative (PR #183036)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 25 07:21:56 PST 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) {
----------------
ldionne wrote:
As discussed, let's try implementing the non-existent benchmark in a way that reduces branch predictions. Then, if the existent and non-existent cases have basically the same execution time, I think it would be fine to remove the non-existent case.
https://github.com/llvm/llvm-project/pull/183036
More information about the libcxx-commits
mailing list