Skip to content

Commit dd788af

Browse files
authored
Reapply "[libc++][ranges] Add benchmarks for the from_range constructors of vector and deque." (#67753)
This reverts commit 10edd5d and guards against older versions of GCC to work around the problem.
1 parent ec9d80e commit dd788af

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

libcxx/benchmarks/CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,27 @@ set(BENCHMARK_LIBCXX_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-libcxx)
7676
set(BENCHMARK_NATIVE_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native)
7777

7878
add_library( cxx-benchmarks-flags INTERFACE)
79-
target_compile_features( cxx-benchmarks-flags INTERFACE cxx_std_20)
79+
80+
# TODO(cmake): remove. This is a workaround to prevent older versions of GCC
81+
# from failing the configure step because they don't support C++23.
82+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "13.0")
83+
return()
84+
endif()
85+
#TODO(cmake): remove the `add_compile_options`. Currently we have to explicitly
86+
# pass the `std:c++latest` flag on Windows to work around an issue where
87+
# requesting `cxx_std_23` results in an error -- somehow CMake fails to
88+
# translate the `c++23` flag into `c++latest`, and the highest numbered C++
89+
# version that MSVC flags support is C++20.
90+
if (MSVC)
91+
add_compile_options(/std:c++latest)
92+
# ibm-clang does not recognize the cxx_std_23 flag, so use this as a temporary
93+
# workaround on AIX as well.
94+
elseif (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
95+
add_compile_options(-std=c++23)
96+
else()
97+
target_compile_features( cxx-benchmarks-flags INTERFACE cxx_std_23)
98+
endif()
99+
80100
target_compile_options( cxx-benchmarks-flags INTERFACE -fsized-deallocation -nostdinc++)
81101
target_include_directories(cxx-benchmarks-flags INTERFACE "${LIBCXX_GENERATED_INCLUDE_DIR}"
82102
INTERFACE "${BENCHMARK_LIBCXX_INSTALL}/include"

libcxx/benchmarks/ContainerBenchmarks.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ void BM_ConstructIterIter(benchmark::State& st, Container, GenInputs gen) {
6969
}
7070
}
7171

72+
template <class Container, class GenInputs>
73+
void BM_ConstructFromRange(benchmark::State& st, Container, GenInputs gen) {
74+
auto in = gen(st.range(0));
75+
benchmark::DoNotOptimize(&in);
76+
while (st.KeepRunning()) {
77+
Container c(std::from_range, in);
78+
DoNotOptimizeData(c);
79+
}
80+
}
81+
7282
template <class Container, class GenInputs>
7383
void BM_InsertValue(benchmark::State& st, Container c, GenInputs gen) {
7484
auto in = gen(st.range(0));

libcxx/benchmarks/deque.bench.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ BENCHMARK_CAPTURE(BM_ConstructIterIter, deque_size_t, std::deque<size_t>{}, getR
3030
BENCHMARK_CAPTURE(BM_ConstructIterIter, deque_string, std::deque<std::string>{}, getRandomStringInputs)
3131
->Arg(TestNumInputs);
3232

33+
BENCHMARK_CAPTURE(BM_ConstructFromRange, deque_char, std::deque<char>{}, getRandomIntegerInputs<char>)
34+
->Arg(TestNumInputs);
35+
36+
BENCHMARK_CAPTURE(BM_ConstructFromRange, deque_size_t, std::deque<size_t>{}, getRandomIntegerInputs<size_t>)
37+
->Arg(TestNumInputs);
38+
39+
BENCHMARK_CAPTURE(BM_ConstructFromRange, deque_string, std::deque<std::string>{}, getRandomStringInputs)
40+
->Arg(TestNumInputs);
41+
3342
BENCHMARK_MAIN();

libcxx/benchmarks/vector_operations.bench.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_size_t, std::vector<size_t>{}, ge
3030
BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_string, std::vector<std::string>{}, getRandomStringInputs)
3131
->Arg(TestNumInputs);
3232

33+
BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_char, std::vector<char>{}, getRandomIntegerInputs<char>)
34+
->Arg(TestNumInputs);
35+
36+
BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_size_t, std::vector<size_t>{}, getRandomIntegerInputs<size_t>)
37+
->Arg(TestNumInputs);
38+
39+
BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_string, std::vector<std::string>{}, getRandomStringInputs)
40+
->Arg(TestNumInputs);
41+
3342
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)