Skip to content

Commit 91eb3be

Browse files
committed
Refactor tests
1 parent c9c6fb9 commit 91eb3be

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

libcxx/docs/ReleaseNotes/20.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ Improvements and New Features
6969
- The ``_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY`` ABI configuration was added, which allows storing valid bounds
7070
in ``std::array::iterator`` and detecting OOB accesses when the appropriate hardening mode is enabled.
7171

72-
- The input iterator overload of `assign(_InputIterator, _InputIterator)` in `std::vector<_Tp, _Allocator>` has been
73-
optimized, resulting in a performance improvement of up to 3.7x.
72+
- The input iterator overload of `assign(_InputIterator, _InputIterator)` in `std::vector<_Tp, _Allocator>` has been
73+
optimized, resulting in a performance improvement of up to 2x for trivial element types (e.g., `std::vector<int>`),
74+
and up to 3.4x for non-trivial element types (e.g., `std::vector<std::vector<int>>`).
7475

7576
Deprecations and Removals
7677
-------------------------

libcxx/test/benchmarks/ContainerBenchmarks.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,11 @@ void BM_Assignment(benchmark::State& st, Container) {
5151
}
5252
}
5353

54-
template <class Container,
55-
class GenInputs,
56-
typename std::enable_if<std::is_trivial<typename Container::value_type>::value>::type* = nullptr>
54+
template <std::size_t... sz, typename Container, typename GenInputs>
5755
void BM_AssignInputIterIter(benchmark::State& st, Container c, GenInputs gen) {
58-
auto in = gen(st.range(1));
59-
c.resize(st.range(0));
60-
benchmark::DoNotOptimize(&in);
61-
benchmark::DoNotOptimize(&c);
62-
for (auto _ : st) {
63-
c.assign(cpp17_input_iterator(in.begin()), cpp17_input_iterator(in.end()));
64-
benchmark::ClobberMemory();
65-
}
66-
}
67-
68-
template <class Container,
69-
class GenInputs,
70-
typename std::enable_if<!std::is_trivial<typename Container::value_type>::value>::type* = nullptr>
71-
void BM_AssignInputIterIter(benchmark::State& st, Container c, GenInputs gen) {
72-
auto v = gen(1, 100);
56+
auto v = gen(1, sz...);
7357
c.resize(st.range(0), v[0]);
74-
auto in = gen(st.range(1), 32);
58+
auto in = gen(st.range(1), sz...);
7559
benchmark::DoNotOptimize(&in);
7660
benchmark::DoNotOptimize(&c);
7761
for (auto _ : st) {

libcxx/test/benchmarks/vector_operations.bench.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ BENCHMARK(bm_grow<std::deque<int>>);
8282
BENCHMARK_CAPTURE(BM_AssignInputIterIter, vector_int, std::vector<int>{}, getRandomIntegerInputs<int>)
8383
->Args({TestNumInputs, TestNumInputs});
8484

85-
BENCHMARK_CAPTURE(BM_AssignInputIterIter, vector_string, std::vector<std::string>{}, getRandomStringInputsWithLength)
85+
BENCHMARK_CAPTURE(
86+
BM_AssignInputIterIter<32>, vector_string, std::vector<std::string>{}, getRandomStringInputsWithLength)
8687
->Args({TestNumInputs, TestNumInputs});
8788

88-
BENCHMARK_CAPTURE(
89-
BM_AssignInputIterIter, vector_vector_int, std::vector<std::vector<int>>{}, getRandomIntegerInputsWithLength<int>)
89+
BENCHMARK_CAPTURE(BM_AssignInputIterIter<100>,
90+
vector_vector_int,
91+
std::vector<std::vector<int>>{},
92+
getRandomIntegerInputsWithLength<int>)
9093
->Args({TestNumInputs, TestNumInputs});
9194

9295
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)