1#include <unordered_set>
2#include <vector>
3#include <cstdint>
4
5#include "benchmark/benchmark.h"
6#include "GenerateInput.hpp"
7
8constexpr std::size_t TestNumInputs = 1024;
9
10template <class GenInputs>
11void BM_Sort(benchmark::State& st, GenInputs gen) {
12    using ValueType = typename decltype(gen(0))::value_type;
13    const auto in = gen(st.range(0));
14    std::vector<ValueType> inputs[5];
15    auto reset_inputs = [&]() {
16        for (auto& C : inputs) {
17            C = in;
18            benchmark::DoNotOptimize(C.data());
19        }
20    };
21    reset_inputs();
22    while (st.KeepRunning()) {
23        for (auto& I : inputs) {
24            std::sort(I.data(), I.data() + I.size());
25            benchmark::DoNotOptimize(I.data());
26        }
27        st.PauseTiming();
28        reset_inputs();
29        benchmark::ClobberMemory();
30        st.ResumeTiming();
31    }
32}
33
34BENCHMARK_CAPTURE(BM_Sort, random_uint32,
35    getRandomIntegerInputs<uint32_t>)->Arg(TestNumInputs);
36
37BENCHMARK_CAPTURE(BM_Sort, sorted_ascending_uint32,
38    getSortedIntegerInputs<uint32_t>)->Arg(TestNumInputs);
39
40BENCHMARK_CAPTURE(BM_Sort, sorted_descending_uint32,
41    getReverseSortedIntegerInputs<uint32_t>)->Arg(TestNumInputs);
42
43BENCHMARK_CAPTURE(BM_Sort, single_element_uint32,
44    getDuplicateIntegerInputs<uint32_t>)->Arg(TestNumInputs);
45
46BENCHMARK_CAPTURE(BM_Sort, pipe_organ_uint32,
47    getPipeOrganIntegerInputs<uint32_t>)->Arg(TestNumInputs);
48
49BENCHMARK_CAPTURE(BM_Sort, random_strings,
50    getRandomStringInputs)->Arg(TestNumInputs);
51
52BENCHMARK_CAPTURE(BM_Sort, sorted_ascending_strings,
53    getSortedStringInputs)->Arg(TestNumInputs);
54
55BENCHMARK_CAPTURE(BM_Sort, sorted_descending_strings,
56    getReverseSortedStringInputs)->Arg(TestNumInputs);
57
58BENCHMARK_CAPTURE(BM_Sort, single_element_strings,
59    getDuplicateStringInputs)->Arg(TestNumInputs);
60
61
62BENCHMARK_MAIN();
63