[libcxx-commits] [libcxx] b90f606 - [libc++] Rename container benchmarks for consistency and precision (#181178)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Mar 11 10:49:13 PDT 2026
Author: Louis Dionne
Date: 2026-03-11T13:49:09-04:00
New Revision: b90f606c58e787e2cb3d5aebe8f14ab08657b3db
URL: https://github.com/llvm/llvm-project/commit/b90f606c58e787e2cb3d5aebe8f14ab08657b3db
DIFF: https://github.com/llvm/llvm-project/commit/b90f606c58e787e2cb3d5aebe8f14ab08657b3db.diff
LOG: [libc++] Rename container benchmarks for consistency and precision (#181178)
Added:
Modified:
libcxx/docs/CodingGuidelines.rst
libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
libcxx/test/benchmarks/containers/sequence/sequence_container_benchmarks.h
libcxx/test/benchmarks/containers/sequence/vector_bool.bench.cpp
Removed:
################################################################################
diff --git a/libcxx/docs/CodingGuidelines.rst b/libcxx/docs/CodingGuidelines.rst
index c1ea6acf58df6..d91e3f22f36b6 100644
--- a/libcxx/docs/CodingGuidelines.rst
+++ b/libcxx/docs/CodingGuidelines.rst
@@ -210,3 +210,18 @@ prevent compilers from generating said debug information. Aliases inside type tr
should be annotated for the same reason.
This is enforced by the clang-tidy check ``libcpp-nodebug-on-aliases``.
+
+Naming benchmarks
+=================
+
+Libc++ contains several benchmarks. It is helpful to observe some consistency when naming benchmarks since it makes it
+easier to search for and filter benchmark names from various other tools like LNT. In particular, we name benchmarks
+after the function they are measuring, with a few transformations to help filtering:
+
+- Constructors are named ``ctor`` to make the name independent on the container being benchmarked.
+- Copy and move operations use ``Self`` instead of the container type, again to make their name independent from the
+ container being benchmarked.
+
+When multiple benchmarks measure the same function under
diff erent circumstances, we add context as a parenthesis
+after the function signature. For example, ``std::vector<bool>::ctor(Self&&, const allocator_type&) (equal allocators)``
+would be the allocator-aware move constructor for ``std::vector<bool>`` in the case of equal allocators.
diff --git a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
index d1f55f94196fa..cc7b6f4d23a9a 100644
--- a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
+++ b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
@@ -89,7 +89,7 @@ void associative_container_benchmarks(std::string container) {
/////////////////////////
// Constructors
/////////////////////////
- bench("ctor(const&)", [=](auto& st) {
+ bench("ctor(const Self&)", [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size));
Container src(in.begin(), in.end());
@@ -110,7 +110,7 @@ void associative_container_benchmarks(std::string container) {
}
});
- bench("ctor(const&, alloc)", [=](auto& st) {
+ bench("ctor(const Self&, const allocator_type&)", [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size));
Container src(in.begin(), in.end());
@@ -131,7 +131,7 @@ void associative_container_benchmarks(std::string container) {
}
});
- bench("ctor(&&,
diff erent allocs)", [=](auto& st) {
+ bench("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>>;
@@ -213,7 +213,7 @@ void associative_container_benchmarks(std::string container) {
/////////////////////////
// Assignment
/////////////////////////
- bench("operator=(const&) (into cleared Container)", [=](auto& st) {
+ bench("operator=(const Self&) (into cleared Container)", [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size));
Container src(in.begin(), in.end());
@@ -234,7 +234,7 @@ void associative_container_benchmarks(std::string container) {
}
});
- bench("operator=(const&) (into partially populated Container)", [=](auto& st) {
+ bench("operator=(const Self&) (into partially populated Container)", [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size));
Container src(in.begin(), in.end());
@@ -255,7 +255,7 @@ void associative_container_benchmarks(std::string container) {
}
});
- bench("operator=(const&) (into populated Container)", [=](auto& st) {
+ bench("operator=(const Self&) (into populated Container)", [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size));
Container src(in.begin(), in.end());
@@ -273,7 +273,7 @@ void associative_container_benchmarks(std::string container) {
/////////////////////////
// Insertion
/////////////////////////
- bench_non_empty("insert(value) (already present)", [=](auto& st) {
+ bench_non_empty("insert(const value_type&) (already present)", [=](auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size));
Value to_insert = in[in.size() / 2]; // pick any existing value
diff --git a/libcxx/test/benchmarks/containers/sequence/sequence_container_benchmarks.h b/libcxx/test/benchmarks/containers/sequence/sequence_container_benchmarks.h
index 00ec1ded7dc44..92346c38563fb 100644
--- a/libcxx/test/benchmarks/containers/sequence/sequence_container_benchmarks.h
+++ b/libcxx/test/benchmarks/containers/sequence/sequence_container_benchmarks.h
@@ -65,7 +65,7 @@ void sequence_container_benchmarks(std::string container) {
/////////////////////////
if constexpr (std::is_constructible_v<Container, std::size_t>) {
// not all containers provide this constructor
- bench("ctor(size)", [](auto& st) {
+ bench("ctor(size_type)", [](auto& st) {
auto const size = st.range(0);
for ([[maybe_unused]] auto _ : st) {
@@ -76,7 +76,7 @@ void sequence_container_benchmarks(std::string container) {
}
for (auto gen : generators)
- bench("ctor(size, value_type)" + tostr(gen), [gen](auto& st) {
+ bench("ctor(size_type, const value_type&)" + tostr(gen), [gen](auto& st) {
auto const size = st.range(0);
ValueType value = gen();
benchmark::DoNotOptimize(value);
@@ -118,7 +118,7 @@ void sequence_container_benchmarks(std::string container) {
#endif
for (auto gen : generators)
- bench("ctor(const&)" + tostr(gen), [gen](auto& st) {
+ bench("ctor(const Self&)" + tostr(gen), [gen](auto& st) {
auto const size = st.range(0);
Container in;
std::generate_n(std::back_inserter(in), size, gen);
@@ -135,7 +135,7 @@ void sequence_container_benchmarks(std::string container) {
// Assignment
/////////////////////////
for (auto gen : generators)
- bench("operator=(const&)" + tostr(gen), [gen](auto& st) {
+ bench("operator=(const Self&)" + tostr(gen), [gen](auto& st) {
auto const size = st.range(0);
Container in1, in2;
std::generate_n(std::back_inserter(in1), size, gen);
diff --git a/libcxx/test/benchmarks/containers/sequence/vector_bool.bench.cpp b/libcxx/test/benchmarks/containers/sequence/vector_bool.bench.cpp
index 1300c600f57ad..b3f3348adcc91 100644
--- a/libcxx/test/benchmarks/containers/sequence/vector_bool.bench.cpp
+++ b/libcxx/test/benchmarks/containers/sequence/vector_bool.bench.cpp
@@ -21,7 +21,7 @@ static void BM_vector_bool_copy_ctor(benchmark::State& state) {
benchmark::DoNotOptimize(vec2);
}
}
-BENCHMARK(BM_vector_bool_copy_ctor)->Name("vector<bool>(const vector<bool>&)");
+BENCHMARK(BM_vector_bool_copy_ctor)->Name("std::vector<bool>::ctor(const Self&)");
static void BM_vector_bool_move_ctor_alloc_equal(benchmark::State& state) {
std::vector<bool> vec(100, true);
@@ -34,7 +34,7 @@ static void BM_vector_bool_move_ctor_alloc_equal(benchmark::State& state) {
}
}
BENCHMARK(BM_vector_bool_move_ctor_alloc_equal)
- ->Name("vector<bool>(vector<bool>&&, const allocator_type&) (equal allocators)");
+ ->Name("std::vector<bool>::ctor(Self&&, const allocator_type&) (equal allocators)");
#if TEST_STD_VER >= 17
static void BM_vector_bool_move_ctor_alloc_
diff erent(benchmark::State& state) {
@@ -48,7 +48,7 @@ static void BM_vector_bool_move_ctor_alloc_
diff erent(benchmark::State& state) {
}
}
BENCHMARK(BM_vector_bool_move_ctor_alloc_
diff erent)
- ->Name("vector<bool>(vector<bool>&&, const allocator_type&) (
diff erent allocators)");
+ ->Name("std::vector<bool>::ctor(Self&&, const allocator_type&) (
diff erent allocators)");
#endif
static void BM_vector_bool_size_ctor(benchmark::State& state) {
@@ -57,7 +57,7 @@ static void BM_vector_bool_size_ctor(benchmark::State& state) {
benchmark::DoNotOptimize(vec);
}
}
-BENCHMARK(BM_vector_bool_size_ctor)->Name("vector<bool>(size_type, const value_type&)");
+BENCHMARK(BM_vector_bool_size_ctor)->Name("std::vector<bool>::ctor(size_type, const value_type&)");
static void BM_vector_bool_reserve(benchmark::State& state) {
for (auto _ : state) {
@@ -66,7 +66,7 @@ static void BM_vector_bool_reserve(benchmark::State& state) {
benchmark::DoNotOptimize(vec);
}
}
-BENCHMARK(BM_vector_bool_reserve)->Name("vector<bool>::reserve()");
+BENCHMARK(BM_vector_bool_reserve)->Name("std::vector<bool>::reserve()");
static void BM_vector_bool_resize(benchmark::State& state) {
for (auto _ : state) {
@@ -75,6 +75,6 @@ static void BM_vector_bool_resize(benchmark::State& state) {
benchmark::DoNotOptimize(vec);
}
}
-BENCHMARK(BM_vector_bool_resize)->Name("vector<bool>::resize()");
+BENCHMARK(BM_vector_bool_resize)->Name("std::vector<bool>::resize()");
BENCHMARK_MAIN();
More information about the libcxx-commits
mailing list