1 #ifndef BENCHMARK_GENERATE_INPUT_H
2 #define BENCHMARK_GENERATE_INPUT_H
11 static const char Letters
[] = {
14 'A','B','C','D','E','F',
19 'a','b','c','d','e','f',
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
{}());
33 inline char getRandomChar() {
34 std::uniform_int_distribution
<> LettersDist(0, LettersSize
-1);
35 return Letters
[LettersDist(getRandomEngine())];
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
);
51 inline std::vector
<IntT
> getDuplicateIntegerInputs(size_t N
) {
52 std::vector
<IntT
> inputs(N
, static_cast<IntT
>(-1));
57 inline std::vector
<IntT
> getSortedIntegerInputs(size_t N
) {
58 std::vector
<IntT
> inputs
;
59 for (size_t i
=0; i
< N
; i
+= 1)
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
);
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
);
81 inline std::vector
<IntT
> getReverseSortedIntegerInputs(size_t N
) {
82 std::vector
<IntT
> inputs
;
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
);
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()));
109 inline std::vector
<std::string
> getDuplicateStringInputs(size_t N
) {
110 std::vector
<std::string
> inputs(N
, getRandomString(1024));
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));
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());
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());
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());
143 #endif // BENCHMARK_GENERATE_INPUT_H