1 #ifndef BENCHMARK_GENERATE_INPUT_H
2 #define BENCHMARK_GENERATE_INPUT_H
11 static const char Letters
[] = {
12 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
13 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
14 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
15 static const std::size_t LettersSize
= sizeof(Letters
);
17 inline std::default_random_engine
& getRandomEngine() {
18 static std::default_random_engine
RandEngine(std::random_device
{}());
22 inline char getRandomChar() {
23 std::uniform_int_distribution
<> LettersDist(0, LettersSize
- 1);
24 return Letters
[LettersDist(getRandomEngine())];
28 inline IntT
getRandomInteger(IntT Min
, IntT Max
) {
29 std::uniform_int_distribution
<unsigned long long> dist(Min
, Max
);
30 return static_cast<IntT
>(dist(getRandomEngine()));
33 inline std::string
getRandomString(std::size_t Len
) {
34 std::string
str(Len
, 0);
35 std::generate_n(str
.begin(), Len
, &getRandomChar
);
40 inline std::vector
<IntT
> getDuplicateIntegerInputs(size_t N
) {
41 std::vector
<IntT
> inputs(N
, static_cast<IntT
>(-1));
46 inline std::vector
<IntT
> getSortedIntegerInputs(size_t N
) {
47 std::vector
<IntT
> inputs
;
48 for (size_t i
= 0; i
< N
; i
+= 1)
54 std::vector
<IntT
> getSortedLargeIntegerInputs(size_t N
) {
55 std::vector
<IntT
> inputs
;
56 for (size_t i
= 0; i
< N
; ++i
) {
57 inputs
.push_back(i
+ N
);
63 std::vector
<IntT
> getSortedTopBitsIntegerInputs(size_t N
) {
64 std::vector
<IntT
> inputs
= getSortedIntegerInputs
<IntT
>(N
);
65 for (auto& E
: inputs
)
66 E
<<= ((sizeof(IntT
) / 2) * CHAR_BIT
);
71 inline std::vector
<IntT
> getReverseSortedIntegerInputs(size_t N
) {
72 std::vector
<IntT
> inputs
;
82 std::vector
<IntT
> getPipeOrganIntegerInputs(size_t N
) {
85 for (size_t i
= 0; i
< N
/ 2; ++i
)
87 for (size_t i
= N
/ 2; i
< N
; ++i
)
93 std::vector
<IntT
> getRandomIntegerInputs(size_t N
) {
94 std::vector
<IntT
> inputs
;
95 for (size_t i
= 0; i
< N
; ++i
) {
96 inputs
.push_back(getRandomInteger
<IntT
>(0, std::numeric_limits
<IntT
>::max()));
101 inline std::vector
<std::string
> getDuplicateStringInputs(size_t N
) {
102 std::vector
<std::string
> inputs(N
, getRandomString(1024));
106 inline std::vector
<std::string
> getRandomStringInputs(size_t N
) {
107 std::vector
<std::string
> inputs
;
108 for (size_t i
= 0; i
< N
; ++i
) {
109 inputs
.push_back(getRandomString(1024));
114 inline std::vector
<std::string
> getPrefixedRandomStringInputs(size_t N
) {
115 std::vector
<std::string
> inputs
;
116 constexpr int kSuffixLength
= 32;
117 const std::string prefix
= getRandomString(1024 - kSuffixLength
);
118 for (size_t i
= 0; i
< N
; ++i
) {
119 inputs
.push_back(prefix
+ getRandomString(kSuffixLength
));
124 inline std::vector
<std::string
> getSortedStringInputs(size_t N
) {
125 std::vector
<std::string
> inputs
= getRandomStringInputs(N
);
126 std::sort(inputs
.begin(), inputs
.end());
130 inline std::vector
<std::string
> getReverseSortedStringInputs(size_t N
) {
131 std::vector
<std::string
> inputs
= getSortedStringInputs(N
);
132 std::reverse(inputs
.begin(), inputs
.end());
136 inline std::vector
<const char*> getRandomCStringInputs(size_t N
) {
137 static std::vector
<std::string
> inputs
= getRandomStringInputs(N
);
138 std::vector
<const char*> cinputs
;
139 for (auto const& str
: inputs
)
140 cinputs
.push_back(str
.c_str());
144 #endif // BENCHMARK_GENERATE_INPUT_H