[libcxx-commits] [libcxx] [libc++] Implement single element vector::insert in terms of emplace (PR #210284)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 10 07:46:50 PDT 2026
================
@@ -227,6 +248,27 @@ void sequence_container_benchmarks(std::string container) {
c.erase(c.end() - 1); // avoid growing indefinitely
}
});
+ bench("emplace(middle)" + tostr(gen), [gen](auto& st) {
+ auto const size = st.range(0);
+ std::vector<ValueType> in;
+ std::generate_n(std::back_inserter(in), size, gen);
+ DoNotOptimizeData(in);
+
+ Container c(in.begin(), in.end());
+ DoNotOptimizeData(c);
+
+ ValueType value = gen();
+ benchmark::DoNotOptimize(value);
+
+ for ([[maybe_unused]] auto _ : st) {
+ auto mid = c.begin() + (size / 2); // requires random-access iterators in order to make sense
+ c.emplace(mid, value);
+ DoNotOptimizeData(c);
+
+ c.erase(c.end() - 1); // avoid growing indefinitely
----------------
ldionne wrote:
You could also simplify to use `pop_back`. If you do that, consider changing `insert` benchmarks as a drive-by.
https://github.com/llvm/llvm-project/pull/210284
More information about the libcxx-commits
mailing list