Skip to content

Commit f1bace6

Browse files
feat(bench): add merge sort benchmark (#125)
1 parent 7c0738d commit f1bace6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Brandon Pacewic
2+
// SPDX-License-Identifier: MIT
3+
4+
#include <algorithm>
5+
#include <benchmark/benchmark.h>
6+
#include <cstdint>
7+
#include <random>
8+
#include <vector>
9+
10+
#include "container.h"
11+
12+
using namespace std;
13+
using namespace cpl;
14+
15+
template <class T>
16+
void bench(benchmark::State& state) {
17+
mt19937 gen(96337);
18+
19+
const size_t size = static_cast<size_t>(state.range(0));
20+
21+
vector<T> input(size);
22+
23+
uniform_int_distribution<T> dist(numeric_limits<T>::min(), numeric_limits<T>::max());
24+
ranges::generate(input, [&] { return dist(gen); });
25+
26+
for (auto _ : state) {
27+
benchmark::DoNotOptimize(input);
28+
benchmark::DoNotOptimize(merge_sort(input));
29+
}
30+
}
31+
32+
#pragma GCC diagnostic push
33+
#pragma GCC diagnostic ignored "-Wignored-attributes"
34+
BENCHMARK(bench<int8_t>)->Range(8, 8 << 10);
35+
BENCHMARK(bench<int16_t>)->Range(8, 8 << 10);
36+
BENCHMARK(bench<int32_t>)->Range(8, 8 << 10);
37+
BENCHMARK(bench<int64_t>)->Range(8, 8 << 10);
38+
#pragma GCC diagnostic pop
39+
40+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)