[libcxx-commits] [PATCH] D148850: [libc++] Add test case for benchmarking vector copy

Aditya Kumar via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 21 14:09:52 PDT 2023


hiraditya updated this revision to Diff 515913.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148850/new/

https://reviews.llvm.org/D148850

Files:
  libcxx/benchmarks/ContainerBenchmarks.h
  libcxx/benchmarks/vector_operations.bench.cpp


Index: libcxx/benchmarks/vector_operations.bench.cpp
===================================================================
--- libcxx/benchmarks/vector_operations.bench.cpp
+++ libcxx/benchmarks/vector_operations.bench.cpp
@@ -17,6 +17,14 @@
     vector_byte,
     std::vector<unsigned char>{})->Arg(5140480);
 
+BENCHMARK_CAPTURE(BM_CopyConstruct,
+    vector_int,
+    std::vector<int>{})->Arg(5140480);
+
+BENCHMARK_CAPTURE(BM_CopyContainerInto,
+    vector_int,
+    std::vector<int>{})->Arg(5140480);
+
 BENCHMARK_CAPTURE(BM_ConstructSizeValue,
     vector_byte,
     std::vector<unsigned char>{}, 0)->Arg(5140480);
Index: libcxx/benchmarks/ContainerBenchmarks.h
===================================================================
--- libcxx/benchmarks/ContainerBenchmarks.h
+++ libcxx/benchmarks/ContainerBenchmarks.h
@@ -26,6 +26,40 @@
   }
 }
 
+template <class Container>
+__attribute__((noinline))
+int CopyContainer(Container v1) {
+    auto v = v1;
+    return 0;
+}
+
+template <class Container>
+__attribute__((noinline))
+int CopyContainerInto(const Container &v1, Container &v2) {
+    v2 = v1;
+    return 0;
+}
+
+template <class Container>
+void BM_CopyConstruct(benchmark::State& st, Container) {
+  auto size = st.range(0);
+  Container c(size);
+  for (auto _ : st) {
+    auto v = CopyContainer(c);
+    DoNotOptimizeData(v);
+  }
+}
+
+template <class Container>
+void BM_CopyContainerInto(benchmark::State& st, Container) {
+  auto size = st.range(0);
+  Container c(size);
+  for (auto _ : st) {
+    auto v = CopyContainer(c);
+    DoNotOptimizeData(v);
+  }
+}
+
 template <class Container>
 void BM_ConstructSizeValue(benchmark::State& st, Container, typename Container::value_type const& val) {
   const auto size = st.range(0);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148850.515913.patch
Type: text/x-patch
Size: 1757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230421/7ca51431/attachment-0001.bin>


More information about the libcxx-commits mailing list