Skip to content

Commit 439bef9

Browse files
authored
[libc++] Refactor the sequence container benchmarks (#119763)
Rewrite the sequence container benchmarks to only rely on the actual operations specified in SequenceContainer requirements and add benchmarks for std::list, which is also considered a sequence container. One of the major goals of this refactoring is also to make these container benchmarks run faster so that they can be run more frequently. The existing benchmarks have the significant problem that they take so long to run that they must basically be run overnight. This patch reduces the size of inputs such that the rewritten benchmarks each take at most a minute to run. This patch doesn't touch the string benchmarks, which were not using the generic container benchmark functions previously.
1 parent edc3dc6 commit 439bef9

26 files changed

+716
-536
lines changed

libcxx/test/benchmarks/GenerateInput.h

+28
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <algorithm>
1313
#include <climits>
14+
#include <concepts>
1415
#include <cstddef>
1516
#include <random>
1617
#include <string>
@@ -171,4 +172,31 @@ inline std::vector<const char*> getRandomCStringInputs(std::size_t N) {
171172
return cinputs;
172173
}
173174

175+
template <class T>
176+
struct Generate {
177+
// When the contents don't matter
178+
static T arbitrary();
179+
180+
// Prefer a cheap-to-construct element if possible
181+
static T cheap();
182+
183+
// Prefer an expensive-to-construct element if possible
184+
static T expensive();
185+
};
186+
187+
template <class T>
188+
requires std::integral<T>
189+
struct Generate<T> {
190+
static T arbitrary() { return 42; }
191+
static T cheap() { return 42; }
192+
static T expensive() { return 42; }
193+
};
194+
195+
template <>
196+
struct Generate<std::string> {
197+
static std::string arbitrary() { return "hello world"; }
198+
static std::string cheap() { return "small"; }
199+
static std::string expensive() { return std::string(256, 'x'); }
200+
};
201+
174202
#endif // BENCHMARK_GENERATE_INPUT_H

libcxx/test/benchmarks/Utilities.h

-37
This file was deleted.

libcxx/test/benchmarks/algorithms/algorithms.partition_point.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
1212
#include <array>

libcxx/test/benchmarks/algorithms/lower_bound.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
1212
#include <numeric>

libcxx/test/benchmarks/algorithms/make_heap.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
1212

libcxx/test/benchmarks/algorithms/make_heap_then_sort_heap.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
1212

libcxx/test/benchmarks/algorithms/pop_heap.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
1212

libcxx/test/benchmarks/algorithms/pstl.stable_sort.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010
// UNSUPPORTED: libcpp-has-no-incomplete-pstl
1111

1212
#include <algorithm>

libcxx/test/benchmarks/algorithms/push_heap.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
1212

libcxx/test/benchmarks/algorithms/set_intersection.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
1212
#include <cstdlib>

libcxx/test/benchmarks/algorithms/sort.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
1212

libcxx/test/benchmarks/algorithms/sort_heap.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
1212

libcxx/test/benchmarks/algorithms/stable_sort.bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
1212

0 commit comments

Comments
 (0)