[libcxx-commits] [libcxx] c2ae930 - [libc++] Trim down associative container benchmark sizes (#212252)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Aug 4 05:57:19 PDT 2026
Author: Louis Dionne
Date: 2026-08-04T08:57:14-04:00
New Revision: c2ae9308090e26cc6e3e4ab64c06326061c9572c
URL: https://github.com/llvm/llvm-project/commit/c2ae9308090e26cc6e3e4ab64c06326061c9572c
DIFF: https://github.com/llvm/llvm-project/commit/c2ae9308090e26cc6e3e4ab64c06326061c9572c.diff
LOG: [libc++] Trim down associative container benchmark sizes (#212252)
Based on local measurements, the associative containers are by far the
slowest benchmarks to run. While there is value in benchmarking small
and large sizes, we can significantly cut down benchmark times by
stripping down to only 2 sizes (from 4).
With this patch, the benchmarks go from 3124s to 1766s across the
associative container benchmarks, which is -43% of their execution time,
and corresponds to ~15% of the entire benchmark suite.
Towards #173032
Added:
Modified:
libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
Removed:
################################################################################
diff --git a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
index a6fc117f2c867..82ceefa0459ef 100644
--- a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
+++ b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
@@ -63,10 +63,10 @@ void associative_container_benchmarks(std::string container) {
auto get_key = [](Value const& v) { return adapt_operations<Container>::key_from_value(v); };
auto bench = [&](std::string operation, auto f) {
- benchmark::RegisterBenchmark(container + "::" + operation, f)->Arg(0)->Arg(32)->Arg(1024)->Arg(8192);
+ benchmark::RegisterBenchmark(container + "::" + operation, f)->Arg(0)->Arg(32)->Arg(8192);
};
auto bench_non_empty = [&](std::string operation, auto f) {
- benchmark::RegisterBenchmark(container + "::" + operation, f)->Arg(32)->Arg(1024)->Arg(8192);
+ benchmark::RegisterBenchmark(container + "::" + operation, f)->Arg(32)->Arg(8192);
};
static constexpr bool is_multi_key_container =
@@ -131,7 +131,7 @@ void associative_container_benchmarks(std::string container) {
}
});
- bench("ctor(Self&&, const allocator_type&) (
diff erent allocs)", [=](auto& st) {
+ bench_non_empty("ctor(Self&&, const allocator_type&) (
diff erent allocs)", [=](auto& st) {
using PMRContainer = adapt_operations<Container>::template rebind_alloc<
std::pmr::polymorphic_allocator<typename Container::value_type>>;
@@ -498,11 +498,14 @@ void associative_container_benchmarks(std::string container) {
st.ResumeTiming();
}
};
- bench("insert(iterator, iterator) (all new keys, end)", [=](auto& state) { insert_iter_iter_bench(true, state); });
- bench("insert(iterator, iterator) (all new keys, middle)",
- [=](auto& state) { insert_iter_iter_bench(false, state); });
+ bench_non_empty("insert(iterator, iterator) (all new keys, end)", [=](auto& state) {
+ insert_iter_iter_bench(true, state);
+ });
+ bench_non_empty("insert(iterator, iterator) (all new keys, middle)", [=](auto& state) {
+ insert_iter_iter_bench(false, state);
+ });
- bench("insert(iterator, iterator) (half new keys)", [=](auto& st) {
+ bench_non_empty("insert(iterator, iterator) (half new keys)", [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size));
@@ -526,7 +529,7 @@ void associative_container_benchmarks(std::string container) {
});
if constexpr (is_map_like) {
- bench("insert(iterator, iterator) (product_iterator from same type)", [=](auto& st) {
+ bench_non_empty("insert(iterator, iterator) (product_iterator from same type)", [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size + (size / 10)));
Container source(in.begin(), in.end());
@@ -545,7 +548,7 @@ void associative_container_benchmarks(std::string container) {
});
#if TEST_STD_VER >= 23
- bench("insert(iterator, iterator) (product_iterator from zip_view)", [=](auto& st) {
+ bench_non_empty("insert(iterator, iterator) (product_iterator from zip_view)", [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Key> keys = generate_unique_keys(size + (size / 10));
std::sort(keys.begin(), keys.end());
@@ -652,7 +655,7 @@ void associative_container_benchmarks(std::string container) {
}
});
- bench("erase(iterator, iterator) (erase half the container)", [=](auto& st) {
+ bench_non_empty("erase(iterator, iterator) (erase half the container)", [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size));
Container c(in.begin(), in.end());
More information about the libcxx-commits
mailing list