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

Konstantin Varlamov via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 5 15:58:06 PDT 2023


Author: varconst
Date: 2023-09-05T15:57:45-07:00
New Revision: 390ac823178fc1073612b4c8a38835f441138d9d

URL: https://github.com/llvm/llvm-project/commit/390ac823178fc1073612b4c8a38835f441138d9d
DIFF: https://github.com/llvm/llvm-project/commit/390ac823178fc1073612b4c8a38835f441138d9d.diff

LOG: [libc++][ranges] Add benchmarks for the `from_range` constructors of `vector` and `deque`.

Differential Revision: https://reviews.llvm.org/D150747

Added: 
    

Modified: 
    libcxx/benchmarks/CMakeLists.txt
    libcxx/benchmarks/ContainerBenchmarks.h
    libcxx/benchmarks/deque.bench.cpp
    libcxx/benchmarks/vector_operations.bench.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/benchmarks/CMakeLists.txt b/libcxx/benchmarks/CMakeLists.txt
index 92f295ef399008..d79c6478c266ed 100644
--- a/libcxx/benchmarks/CMakeLists.txt
+++ b/libcxx/benchmarks/CMakeLists.txt
@@ -76,7 +76,16 @@ set(BENCHMARK_LIBCXX_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-libcxx)
 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)
+#TODO(cmake): remove the `add_compile_options`. Currently we have to explicitly
+# pass the `std:c++latest` flag on Windows to work around an issue where
+# requesting `cxx_std_23` results in an error -- somehow CMake fails to
+# translate the `c++23` flag into `c++latest`, and the highest numbered C++
+# version that MSVC flags support is C++20.
+if (MSVC)
+  add_compile_options(/std:c++latest)
+else()
+  target_compile_features( cxx-benchmarks-flags INTERFACE cxx_std_23)
+endif()
 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"

diff  --git a/libcxx/benchmarks/ContainerBenchmarks.h b/libcxx/benchmarks/ContainerBenchmarks.h
index bf027f5f41469d..5ab6f619b85a8d 100644
--- a/libcxx/benchmarks/ContainerBenchmarks.h
+++ b/libcxx/benchmarks/ContainerBenchmarks.h
@@ -69,6 +69,16 @@ void BM_ConstructIterIter(benchmark::State& st, Container, GenInputs gen) {
   }
 }
 
+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));

diff  --git a/libcxx/benchmarks/deque.bench.cpp b/libcxx/benchmarks/deque.bench.cpp
index ced2ba230f6c82..d6dadaa3f23e4d 100644
--- a/libcxx/benchmarks/deque.bench.cpp
+++ b/libcxx/benchmarks/deque.bench.cpp
@@ -30,4 +30,13 @@ BENCHMARK_CAPTURE(BM_ConstructIterIter, deque_size_t, std::deque<size_t>{}, getR
 BENCHMARK_CAPTURE(BM_ConstructIterIter, deque_string, 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);
+
 BENCHMARK_MAIN();

diff  --git a/libcxx/benchmarks/vector_operations.bench.cpp b/libcxx/benchmarks/vector_operations.bench.cpp
index e02f0ee0c11caf..be0bee6b645612 100644
--- a/libcxx/benchmarks/vector_operations.bench.cpp
+++ b/libcxx/benchmarks/vector_operations.bench.cpp
@@ -30,4 +30,13 @@ BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_size_t, std::vector<size_t>{}, ge
 BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_string, 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();


        


More information about the libcxx-commits mailing list