[libcxx-commits] [PATCH] D150747: [libc++][ranges] Add benchmarks for the `from_range` constructors of `vector` and `deque`.

Konstantin Varlamov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 16 19:06:48 PDT 2023


var-const created this revision.
Herald added a project: All.
var-const requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150747

Files:
  libcxx/benchmarks/CMakeLists.txt
  libcxx/benchmarks/ContainerBenchmarks.h
  libcxx/benchmarks/deque.bench.cpp
  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
@@ -36,5 +36,20 @@
   std::vector<std::string>{},
   getRandomStringInputs)->Arg(TestNumInputs);
 
+BENCHMARK_CAPTURE(BM_ConstructFromRange,
+  vector_char,
+  std::vector<char>{},
+  getRandomIntegerInputs<char>)->Arg(TestNumInputs);
+
+BENCHMARK_CAPTURE(BM_ConstructFromRange,
+  vector_size_t,
+  std::vector<size_t>{},
+  getRandomIntegerInputs<size_t>)->Arg(TestNumInputs);
+
+BENCHMARK_CAPTURE(BM_ConstructFromRange,
+  vector_string,
+  std::vector<std::string>{},
+  getRandomStringInputs)->Arg(TestNumInputs);
+
 
 BENCHMARK_MAIN();
Index: libcxx/benchmarks/deque.bench.cpp
===================================================================
--- libcxx/benchmarks/deque.bench.cpp
+++ libcxx/benchmarks/deque.bench.cpp
@@ -40,6 +40,21 @@
   std::deque<std::string>{},
   getRandomStringInputs)->Arg(TestNumInputs);
 
+BENCHMARK_CAPTURE(BM_ConstructFromRange,
+  deque_char,
+  std::deque<char>{},
+  getRandomIntegerInputs<char>)->Arg(TestNumInputs);
+
+BENCHMARK_CAPTURE(BM_ConstructFromRange,
+  deque_size_t,
+  std::deque<size_t>{},
+  getRandomIntegerInputs<size_t>)->Arg(TestNumInputs);
+
+BENCHMARK_CAPTURE(BM_ConstructFromRange,
+  deque_string,
+  std::deque<std::string>{},
+  getRandomStringInputs)->Arg(TestNumInputs);
+
 
 
 
Index: libcxx/benchmarks/ContainerBenchmarks.h
===================================================================
--- libcxx/benchmarks/ContainerBenchmarks.h
+++ libcxx/benchmarks/ContainerBenchmarks.h
@@ -47,6 +47,16 @@
     }
 }
 
+template <class Container, class GenInputs>
+void BM_ConstructFromRange(benchmark::State& st, Container, GenInputs gen) {
+    auto in = gen(st.range(0));
+    benchmark::DoNotOptimize(&in);
+    while (st.KeepRunning()) {
+        Container c(std::from_range, in);
+        DoNotOptimizeData(c);
+    }
+}
+
 template <class Container, class GenInputs>
 void BM_InsertValue(benchmark::State& st, Container c, GenInputs gen) {
     auto in = gen(st.range(0));
Index: libcxx/benchmarks/CMakeLists.txt
===================================================================
--- libcxx/benchmarks/CMakeLists.txt
+++ libcxx/benchmarks/CMakeLists.txt
@@ -1,4 +1,4 @@
-if (CMAKE_VERSION VERSION_LESS 3.17)
+if (CMAKE_VERSION VERSION_LESS 3.20)
   message(WARNING "The libc++ benchmarks won't be available because the version of CMake is too old to support them.")
   return()
 endif()
@@ -81,7 +81,7 @@
 set(BENCHMARK_NATIVE_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native)
 
 add_library(               cxx-benchmarks-flags INTERFACE)
-target_compile_features(   cxx-benchmarks-flags INTERFACE cxx_std_20)
+target_compile_features(   cxx-benchmarks-flags INTERFACE cxx_std_23)
 target_compile_options(    cxx-benchmarks-flags INTERFACE -fsized-deallocation -nostdinc++)
 target_include_directories(cxx-benchmarks-flags INTERFACE "${LIBCXX_GENERATED_INCLUDE_DIR}"
                                                 INTERFACE "${BENCHMARK_LIBCXX_INSTALL}/include"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150747.522879.patch
Type: text/x-patch
Size: 3159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230517/38fd0bac/attachment.bin>


More information about the libcxx-commits mailing list