[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
Tue Nov 26 14:18:20 PST 2024


================
@@ -69,4 +69,17 @@ BENCHMARK(bm_grow<std::string>);
 BENCHMARK(bm_grow<std::unique_ptr<int>>);
 BENCHMARK(bm_grow<std::deque<int>>);
 
+BENCHMARK_CAPTURE(BM_AssignInputIterIter, vector_int, std::vector<int>{}, getRandomIntegerInputs<int>)
+    ->Args({TestNumInputs, TestNumInputs});
+
+BENCHMARK_CAPTURE(
+    BM_AssignInputIterIter<32>, vector_string, std::vector<std::string>{}, getRandomStringInputsWithLength)
+    ->Args({TestNumInputs, TestNumInputs});
+
+BENCHMARK_CAPTURE(BM_AssignInputIterIter<100>,
----------------
winner245 wrote:

> I don't fully understand the benefit of benchmarking both vector<vector<int>> and vector<string>. Can you explain (or point me to prior discussion on this PR that explains it in case I missed it)?

Initially, this PR analyzed the performance improvements for `std::vector<T>` in two separate cases:

1. T is a trivial type, such as `vector<int>`
2. T is a non-trivial type, such as `vector<string>`

Later, while addressing comments from @philnik777, I realized that the performance improvement should be more significant if T is a more complex non-trivial type. Therefore, I also benchmarked `vector<vector<int>>`, where `T = vector<int>`. My tests confirmed that as T progresses from trivial to non-trivial and to even more complex non-trivial types, we observe growing improvements. 

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


More information about the libcxx-commits mailing list