[libcxx-commits] [libcxx] Optimize input iterator overload of `std::vector::assign(first, last)` (PR #113852)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 15 06:43:35 PST 2024
================
@@ -48,6 +49,35 @@ void BM_Assignment(benchmark::State& st, Container) {
}
}
+template <class Container,
+ class GenInputs,
+ typename std::enable_if<std::is_trivial<typename Container::value_type>::value>::type* = nullptr>
+void BM_AssignInputIterIter(benchmark::State& st, Container c, GenInputs gen) {
+ auto in = gen(st.range(1));
+ c.resize(st.range(0));
+ benchmark::DoNotOptimize(&in);
+ benchmark::DoNotOptimize(&c);
+ for (auto _ : st) {
+ c.assign(cpp17_input_iterator(in.begin()), cpp17_input_iterator(in.end()));
+ benchmark::ClobberMemory();
+ }
+}
+
+template <class Container,
+ class GenInputs,
+ typename std::enable_if<!std::is_trivial<typename Container::value_type>::value>::type* = nullptr>
+void BM_AssignInputIterIter(benchmark::State& st, Container c, GenInputs gen) {
+ auto v = gen(1, 100);
+ c.resize(st.range(0), v[0]);
+ auto in = gen(st.range(1), 32);
+ benchmark::DoNotOptimize(&in);
+ benchmark::DoNotOptimize(&c);
+ for (auto _ : st) {
+ c.assign(cpp17_input_iterator(in.begin()), cpp17_input_iterator(in.end()));
+ benchmark::ClobberMemory();
+ }
+}
----------------
philnik777 wrote:
The only difference between these two seems to be the initialization of `c`. Can't we use the same strategy for trivial types as we do for non-trivial types?
https://github.com/llvm/llvm-project/pull/113852
More information about the libcxx-commits
mailing list