diff --git a/libcxx/benchmarks/CMakeLists.txt b/libcxx/benchmarks/CMakeLists.txt --- a/libcxx/benchmarks/CMakeLists.txt +++ b/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" diff --git a/libcxx/benchmarks/ContainerBenchmarks.h b/libcxx/benchmarks/ContainerBenchmarks.h --- a/libcxx/benchmarks/ContainerBenchmarks.h +++ b/libcxx/benchmarks/ContainerBenchmarks.h @@ -47,6 +47,16 @@ } } +template +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 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 --- a/libcxx/benchmarks/deque.bench.cpp +++ b/libcxx/benchmarks/deque.bench.cpp @@ -40,6 +40,21 @@ std::deque{}, getRandomStringInputs)->Arg(TestNumInputs); +BENCHMARK_CAPTURE(BM_ConstructFromRange, + deque_char, + std::deque{}, + getRandomIntegerInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_ConstructFromRange, + deque_size_t, + std::deque{}, + getRandomIntegerInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_ConstructFromRange, + deque_string, + std::deque{}, + getRandomStringInputs)->Arg(TestNumInputs); + diff --git a/libcxx/benchmarks/vector_operations.bench.cpp b/libcxx/benchmarks/vector_operations.bench.cpp --- a/libcxx/benchmarks/vector_operations.bench.cpp +++ b/libcxx/benchmarks/vector_operations.bench.cpp @@ -36,5 +36,20 @@ std::vector{}, getRandomStringInputs)->Arg(TestNumInputs); +BENCHMARK_CAPTURE(BM_ConstructFromRange, + vector_char, + std::vector{}, + getRandomIntegerInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_ConstructFromRange, + vector_size_t, + std::vector{}, + getRandomIntegerInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_ConstructFromRange, + vector_string, + std::vector{}, + getRandomStringInputs)->Arg(TestNumInputs); + BENCHMARK_MAIN();