Home | History | Annotate | Download | only in benchmarks
      1 #include <unordered_set>
      2 #include <vector>
      3 #include <cstdint>
      4 
      5 #include "benchmark/benchmark_api.h"
      6 #include "GenerateInput.hpp"
      7 
      8 constexpr std::size_t TestNumInputs = 1024;
      9 
     10 template <class GenInputs>
     11 void 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 
     34 BENCHMARK_CAPTURE(BM_Sort, random_uint32,
     35     getRandomIntegerInputs<uint32_t>)->Arg(TestNumInputs);
     36 
     37 BENCHMARK_CAPTURE(BM_Sort, sorted_ascending_uint32,
     38     getSortedIntegerInputs<uint32_t>)->Arg(TestNumInputs);
     39 
     40 BENCHMARK_CAPTURE(BM_Sort, sorted_descending_uint32,
     41     getReverseSortedIntegerInputs<uint32_t>)->Arg(TestNumInputs);
     42 
     43 BENCHMARK_CAPTURE(BM_Sort, single_element_uint32,
     44     getDuplicateIntegerInputs<uint32_t>)->Arg(TestNumInputs);
     45 
     46 BENCHMARK_CAPTURE(BM_Sort, pipe_organ_uint32,
     47     getPipeOrganIntegerInputs<uint32_t>)->Arg(TestNumInputs);
     48 
     49 BENCHMARK_CAPTURE(BM_Sort, random_strings,
     50     getRandomStringInputs)->Arg(TestNumInputs);
     51 
     52 BENCHMARK_CAPTURE(BM_Sort, sorted_ascending_strings,
     53     getSortedStringInputs)->Arg(TestNumInputs);
     54 
     55 BENCHMARK_CAPTURE(BM_Sort, sorted_descending_strings,
     56     getReverseSortedStringInputs)->Arg(TestNumInputs);
     57 
     58 BENCHMARK_CAPTURE(BM_Sort, single_element_strings,
     59     getDuplicateStringInputs)->Arg(TestNumInputs);
     60 
     61 
     62 BENCHMARK_MAIN()
     63