[lld][WebAssembly] Reinstate mistakenly disabled test. NFC
[llvm-project.git] / libcxx / benchmarks / GenerateInput.h
blob3e63f8413303fc3cf488ff9ade60b247b2de9d73
1 #ifndef BENCHMARK_GENERATE_INPUT_H
2 #define BENCHMARK_GENERATE_INPUT_H
4 #include <algorithm>
5 #include <random>
6 #include <vector>
7 #include <string>
8 #include <climits>
9 #include <cstddef>
11 static const char Letters[] = {
12 '0','1','2','3','4',
13 '5','6','7','8','9',
14 'A','B','C','D','E','F',
15 'G','H','I','J','K',
16 'L','M','N','O','P',
17 'Q','R','S','T','U',
18 'V','W','X','Y','Z',
19 'a','b','c','d','e','f',
20 'g','h','i','j','k',
21 'l','m','n','o','p',
22 'q','r','s','t','u',
23 'v','w','x','y','z'
25 static const std::size_t LettersSize = sizeof(Letters);
27 inline std::default_random_engine& getRandomEngine() {
28 static std::default_random_engine RandEngine(std::random_device{}());
29 return RandEngine;
33 inline char getRandomChar() {
34 std::uniform_int_distribution<> LettersDist(0, LettersSize-1);
35 return Letters[LettersDist(getRandomEngine())];
38 template <class IntT>
39 inline IntT getRandomInteger(IntT Min, IntT Max) {
40 std::uniform_int_distribution<unsigned long long> dist(Min, Max);
41 return static_cast<IntT>(dist(getRandomEngine()));
44 inline std::string getRandomString(std::size_t Len) {
45 std::string str(Len, 0);
46 std::generate_n(str.begin(), Len, &getRandomChar);
47 return str;
50 template <class IntT>
51 inline std::vector<IntT> getDuplicateIntegerInputs(size_t N) {
52 std::vector<IntT> inputs(N, static_cast<IntT>(-1));
53 return inputs;
56 template <class IntT>
57 inline std::vector<IntT> getSortedIntegerInputs(size_t N) {
58 std::vector<IntT> inputs;
59 for (size_t i=0; i < N; i += 1)
60 inputs.push_back(i);
61 return inputs;
64 template <class IntT>
65 std::vector<IntT> getSortedLargeIntegerInputs(size_t N) {
66 std::vector<IntT> inputs;
67 for (size_t i=0; i < N; ++i) {
68 inputs.push_back(i + N);
70 return inputs;
73 template <class IntT>
74 std::vector<IntT> getSortedTopBitsIntegerInputs(size_t N) {
75 std::vector<IntT> inputs = getSortedIntegerInputs<IntT>(N);
76 for (auto& E : inputs) E <<= ((sizeof(IntT) / 2) * CHAR_BIT);
77 return inputs;
80 template <class IntT>
81 inline std::vector<IntT> getReverseSortedIntegerInputs(size_t N) {
82 std::vector<IntT> inputs;
83 std::size_t i = N;
84 while (i > 0) {
85 --i;
86 inputs.push_back(i);
88 return inputs;
91 template <class IntT>
92 std::vector<IntT> getPipeOrganIntegerInputs(size_t N) {
93 std::vector<IntT> v; v.reserve(N);
94 for (size_t i = 0; i < N/2; ++i) v.push_back(i);
95 for (size_t i = N/2; i < N; ++i) v.push_back(N - i);
96 return v;
100 template <class IntT>
101 std::vector<IntT> getRandomIntegerInputs(size_t N) {
102 std::vector<IntT> inputs;
103 for (size_t i=0; i < N; ++i) {
104 inputs.push_back(getRandomInteger<IntT>(0, std::numeric_limits<IntT>::max()));
106 return inputs;
109 inline std::vector<std::string> getDuplicateStringInputs(size_t N) {
110 std::vector<std::string> inputs(N, getRandomString(1024));
111 return inputs;
114 inline std::vector<std::string> getRandomStringInputs(size_t N) {
115 std::vector<std::string> inputs;
116 for (size_t i=0; i < N; ++i) {
117 inputs.push_back(getRandomString(1024));
119 return inputs;
122 inline std::vector<std::string> getSortedStringInputs(size_t N) {
123 std::vector<std::string> inputs = getRandomStringInputs(N);
124 std::sort(inputs.begin(), inputs.end());
125 return inputs;
128 inline std::vector<std::string> getReverseSortedStringInputs(size_t N) {
129 std::vector<std::string> inputs = getSortedStringInputs(N);
130 std::reverse(inputs.begin(), inputs.end());
131 return inputs;
134 inline std::vector<const char*> getRandomCStringInputs(size_t N) {
135 static std::vector<std::string> inputs = getRandomStringInputs(N);
136 std::vector<const char*> cinputs;
137 for (auto const& str : inputs)
138 cinputs.push_back(str.c_str());
139 return cinputs;
143 #endif // BENCHMARK_GENERATE_INPUT_H