[libcxx-commits] [libcxx] [libc++] Speed up vector<bool> copy/move-ctors [1/3] (PR #120132)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 20 08:55:40 PST 2025


================
@@ -39,6 +39,36 @@ void BM_CopyConstruct(benchmark::State& st, Container) {
   }
 }
 
+template <class Container>
+void BM_MoveConstruct(benchmark::State& st, Container) {
+  auto size = st.range(0);
+  Container c(size);
+  for (auto _ : st) {
+    auto v = std::move(c);
+    DoNotOptimizeData(v);
+  }
+}
+
+template <class Container, class Allocator>
+void BM_CopyConstruct_Alloc(benchmark::State& st, Container, Allocator a) {
+  auto size = st.range(0);
+  Container c(size);
+  for (auto _ : st) {
+    Container v(c, a);
+    DoNotOptimizeData(v);
+  }
+}
+
+template <class Container, class Allocator>
+void BM_MoveConstruct_Alloc(benchmark::State& st, Container, Allocator a) {
----------------
ldionne wrote:

I'd be okay with dropping this benchmark as well since you're demonstrating your win with the copy benchmark above, even though in principle this benchmark is indeed needed for coverage. I think it's reasonable to remove it since it's tricky to write properly (given the moved-from container).

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


More information about the libcxx-commits mailing list