[libcxx-commits] [libcxx] Optimize input iterator overload of `std::vector::assign(first, last)` (PR #113852)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 22 07:42:58 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();
+  }
+}
----------------
winner245 wrote:

@philnik777 I hope you're doing well! I've addressed all the comments you provided earlier. When you have a moment, could you please take a look? I really appreciate your time and help!

https://github.com/llvm/llvm-project/pull/113852


More information about the libcxx-commits mailing list