Skip to content

Commit 6112450

Browse files
committed
Refactor tests
1 parent 4db31b9 commit 6112450

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
@@ -49,27 +49,11 @@ void BM_Assignment(benchmark::State& st, Container) {
4949
}
5050
}
5151

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

libcxx/test/benchmarks/vector_operations.bench.cpp

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

75-
BENCHMARK_CAPTURE(BM_AssignInputIterIter, vector_string, std::vector<std::string>{}, getRandomStringInputsWithLength)
75+
BENCHMARK_CAPTURE(
76+
BM_AssignInputIterIter<32>, vector_string, std::vector<std::string>{}, getRandomStringInputsWithLength)
7677
->Args({TestNumInputs, TestNumInputs});
7778

78-
BENCHMARK_CAPTURE(
79-
BM_AssignInputIterIter, vector_vector_int, std::vector<std::vector<int>>{}, getRandomIntegerInputsWithLength<int>)
79+
BENCHMARK_CAPTURE(BM_AssignInputIterIter<100>,
80+
vector_vector_int,
81+
std::vector<std::vector<int>>{},
82+
getRandomIntegerInputsWithLength<int>)
8083
->Args({TestNumInputs, TestNumInputs});
8184

8285
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)