Skip to content

Commit 14c1338

Browse files
committed
[libc++] Implement generic associative container benchmarks
This patch implements generic associative container benchmarks for containers with unique keys. In doing so, it replaces the existing std::map benchmarks which were based on the cartesian product infrastructure and were too slow to execute. These new benchmarks aim to strike a balance between exhaustive coverage of all operations in the most interesting case, while executing fairly rapidly (~40s on my machine).
1 parent 9f66062 commit 14c1338

File tree

5 files changed

+625
-932
lines changed

5 files changed

+625
-932
lines changed

libcxx/test/benchmarks/GenerateInput.h

+33
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,36 @@ 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+
static T random() { return getRandomInteger<T>(std::numeric_limits<T>::min(), std::numeric_limits<T>::max()); }
194+
};
195+
196+
template <>
197+
struct Generate<std::string> {
198+
static std::string arbitrary() { return "hello world"; }
199+
static std::string cheap() { return "small"; }
200+
static std::string expensive() { return std::string(256, 'x'); }
201+
static std::string random() {
202+
auto length = getRandomInteger<std::size_t>(1, 1024);
203+
return getRandomString(length);
204+
}
205+
};
206+
174207
#endif // BENCHMARK_GENERATE_INPUT_H

0 commit comments

Comments
 (0)