Skip to content

Commit b90f606

Browse files
authored
[libc++] Rename container benchmarks for consistency and precision (llvm#181178)
1 parent 0da4396 commit b90f606

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

libcxx/docs/CodingGuidelines.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,18 @@ prevent compilers from generating said debug information. Aliases inside type tr
210210
should be annotated for the same reason.
211211

212212
This is enforced by the clang-tidy check ``libcpp-nodebug-on-aliases``.
213+
214+
Naming benchmarks
215+
=================
216+
217+
Libc++ contains several benchmarks. It is helpful to observe some consistency when naming benchmarks since it makes it
218+
easier to search for and filter benchmark names from various other tools like LNT. In particular, we name benchmarks
219+
after the function they are measuring, with a few transformations to help filtering:
220+
221+
- Constructors are named ``ctor`` to make the name independent on the container being benchmarked.
222+
- Copy and move operations use ``Self`` instead of the container type, again to make their name independent from the
223+
container being benchmarked.
224+
225+
When multiple benchmarks measure the same function under different circumstances, we add context as a parenthesis
226+
after the function signature. For example, ``std::vector<bool>::ctor(Self&&, const allocator_type&) (equal allocators)``
227+
would be the allocator-aware move constructor for ``std::vector<bool>`` in the case of equal allocators.

libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void associative_container_benchmarks(std::string container) {
8989
/////////////////////////
9090
// Constructors
9191
/////////////////////////
92-
bench("ctor(const&)", [=](auto& st) {
92+
bench("ctor(const Self&)", [=](auto& st) {
9393
const std::size_t size = st.range(0);
9494
std::vector<Value> in = make_value_types(generate_unique_keys(size));
9595
Container src(in.begin(), in.end());
@@ -110,7 +110,7 @@ void associative_container_benchmarks(std::string container) {
110110
}
111111
});
112112

113-
bench("ctor(const&, alloc)", [=](auto& st) {
113+
bench("ctor(const Self&, const allocator_type&)", [=](auto& st) {
114114
const std::size_t size = st.range(0);
115115
std::vector<Value> in = make_value_types(generate_unique_keys(size));
116116
Container src(in.begin(), in.end());
@@ -131,7 +131,7 @@ void associative_container_benchmarks(std::string container) {
131131
}
132132
});
133133

134-
bench("ctor(&&, different allocs)", [=](auto& st) {
134+
bench("ctor(Self&&, const allocator_type&) (different allocs)", [=](auto& st) {
135135
using PMRContainer = adapt_operations<Container>::template rebind_alloc<
136136
std::pmr::polymorphic_allocator<typename Container::value_type>>;
137137

@@ -213,7 +213,7 @@ void associative_container_benchmarks(std::string container) {
213213
/////////////////////////
214214
// Assignment
215215
/////////////////////////
216-
bench("operator=(const&) (into cleared Container)", [=](auto& st) {
216+
bench("operator=(const Self&) (into cleared Container)", [=](auto& st) {
217217
const std::size_t size = st.range(0);
218218
std::vector<Value> in = make_value_types(generate_unique_keys(size));
219219
Container src(in.begin(), in.end());
@@ -234,7 +234,7 @@ void associative_container_benchmarks(std::string container) {
234234
}
235235
});
236236

237-
bench("operator=(const&) (into partially populated Container)", [=](auto& st) {
237+
bench("operator=(const Self&) (into partially populated Container)", [=](auto& st) {
238238
const std::size_t size = st.range(0);
239239
std::vector<Value> in = make_value_types(generate_unique_keys(size));
240240
Container src(in.begin(), in.end());
@@ -255,7 +255,7 @@ void associative_container_benchmarks(std::string container) {
255255
}
256256
});
257257

258-
bench("operator=(const&) (into populated Container)", [=](auto& st) {
258+
bench("operator=(const Self&) (into populated Container)", [=](auto& st) {
259259
const std::size_t size = st.range(0);
260260
std::vector<Value> in = make_value_types(generate_unique_keys(size));
261261
Container src(in.begin(), in.end());
@@ -273,7 +273,7 @@ void associative_container_benchmarks(std::string container) {
273273
/////////////////////////
274274
// Insertion
275275
/////////////////////////
276-
bench_non_empty("insert(value) (already present)", [=](auto& st) {
276+
bench_non_empty("insert(const value_type&) (already present)", [=](auto& st) {
277277
const std::size_t size = st.range(0);
278278
std::vector<Value> in = make_value_types(generate_unique_keys(size));
279279
Value to_insert = in[in.size() / 2]; // pick any existing value

libcxx/test/benchmarks/containers/sequence/sequence_container_benchmarks.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void sequence_container_benchmarks(std::string container) {
6565
/////////////////////////
6666
if constexpr (std::is_constructible_v<Container, std::size_t>) {
6767
// not all containers provide this constructor
68-
bench("ctor(size)", [](auto& st) {
68+
bench("ctor(size_type)", [](auto& st) {
6969
auto const size = st.range(0);
7070

7171
for ([[maybe_unused]] auto _ : st) {
@@ -76,7 +76,7 @@ void sequence_container_benchmarks(std::string container) {
7676
}
7777

7878
for (auto gen : generators)
79-
bench("ctor(size, value_type)" + tostr(gen), [gen](auto& st) {
79+
bench("ctor(size_type, const value_type&)" + tostr(gen), [gen](auto& st) {
8080
auto const size = st.range(0);
8181
ValueType value = gen();
8282
benchmark::DoNotOptimize(value);
@@ -118,7 +118,7 @@ void sequence_container_benchmarks(std::string container) {
118118
#endif
119119

120120
for (auto gen : generators)
121-
bench("ctor(const&)" + tostr(gen), [gen](auto& st) {
121+
bench("ctor(const Self&)" + tostr(gen), [gen](auto& st) {
122122
auto const size = st.range(0);
123123
Container in;
124124
std::generate_n(std::back_inserter(in), size, gen);
@@ -135,7 +135,7 @@ void sequence_container_benchmarks(std::string container) {
135135
// Assignment
136136
/////////////////////////
137137
for (auto gen : generators)
138-
bench("operator=(const&)" + tostr(gen), [gen](auto& st) {
138+
bench("operator=(const Self&)" + tostr(gen), [gen](auto& st) {
139139
auto const size = st.range(0);
140140
Container in1, in2;
141141
std::generate_n(std::back_inserter(in1), size, gen);

libcxx/test/benchmarks/containers/sequence/vector_bool.bench.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void BM_vector_bool_copy_ctor(benchmark::State& state) {
2121
benchmark::DoNotOptimize(vec2);
2222
}
2323
}
24-
BENCHMARK(BM_vector_bool_copy_ctor)->Name("vector<bool>(const vector<bool>&)");
24+
BENCHMARK(BM_vector_bool_copy_ctor)->Name("std::vector<bool>::ctor(const Self&)");
2525

2626
static void BM_vector_bool_move_ctor_alloc_equal(benchmark::State& state) {
2727
std::vector<bool> vec(100, true);
@@ -34,7 +34,7 @@ static void BM_vector_bool_move_ctor_alloc_equal(benchmark::State& state) {
3434
}
3535
}
3636
BENCHMARK(BM_vector_bool_move_ctor_alloc_equal)
37-
->Name("vector<bool>(vector<bool>&&, const allocator_type&) (equal allocators)");
37+
->Name("std::vector<bool>::ctor(Self&&, const allocator_type&) (equal allocators)");
3838

3939
#if TEST_STD_VER >= 17
4040
static void BM_vector_bool_move_ctor_alloc_different(benchmark::State& state) {
@@ -48,7 +48,7 @@ static void BM_vector_bool_move_ctor_alloc_different(benchmark::State& state) {
4848
}
4949
}
5050
BENCHMARK(BM_vector_bool_move_ctor_alloc_different)
51-
->Name("vector<bool>(vector<bool>&&, const allocator_type&) (different allocators)");
51+
->Name("std::vector<bool>::ctor(Self&&, const allocator_type&) (different allocators)");
5252
#endif
5353

5454
static void BM_vector_bool_size_ctor(benchmark::State& state) {
@@ -57,7 +57,7 @@ static void BM_vector_bool_size_ctor(benchmark::State& state) {
5757
benchmark::DoNotOptimize(vec);
5858
}
5959
}
60-
BENCHMARK(BM_vector_bool_size_ctor)->Name("vector<bool>(size_type, const value_type&)");
60+
BENCHMARK(BM_vector_bool_size_ctor)->Name("std::vector<bool>::ctor(size_type, const value_type&)");
6161

6262
static void BM_vector_bool_reserve(benchmark::State& state) {
6363
for (auto _ : state) {
@@ -66,7 +66,7 @@ static void BM_vector_bool_reserve(benchmark::State& state) {
6666
benchmark::DoNotOptimize(vec);
6767
}
6868
}
69-
BENCHMARK(BM_vector_bool_reserve)->Name("vector<bool>::reserve()");
69+
BENCHMARK(BM_vector_bool_reserve)->Name("std::vector<bool>::reserve()");
7070

7171
static void BM_vector_bool_resize(benchmark::State& state) {
7272
for (auto _ : state) {
@@ -75,6 +75,6 @@ static void BM_vector_bool_resize(benchmark::State& state) {
7575
benchmark::DoNotOptimize(vec);
7676
}
7777
}
78-
BENCHMARK(BM_vector_bool_resize)->Name("vector<bool>::resize()");
78+
BENCHMARK(BM_vector_bool_resize)->Name("std::vector<bool>::resize()");
7979

8080
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)