From 380a80ce791e41f06ee41227a57c545396b84c5c Mon Sep 17 00:00:00 2001 From: BrandonPacewic <92102436+BrandonPacewic@users.noreply.github.com> Date: Tue, 22 Apr 2025 12:26:13 -0700 Subject: [PATCH] feat(bench): add merge sort benchmark --- benchmarks/cpl/merge_sort/bench.cpp | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 benchmarks/cpl/merge_sort/bench.cpp diff --git a/benchmarks/cpl/merge_sort/bench.cpp b/benchmarks/cpl/merge_sort/bench.cpp new file mode 100644 index 0000000..376091f --- /dev/null +++ b/benchmarks/cpl/merge_sort/bench.cpp @@ -0,0 +1,40 @@ +// Copyright (c) Brandon Pacewic +// SPDX-License-Identifier: MIT + +#include +#include +#include +#include +#include + +#include "container.h" + +using namespace std; +using namespace cpl; + +template +void bench(benchmark::State& state) { + mt19937 gen(96337); + + const size_t size = static_cast(state.range(0)); + + vector input(size); + + uniform_int_distribution dist(numeric_limits::min(), numeric_limits::max()); + ranges::generate(input, [&] { return dist(gen); }); + + for (auto _ : state) { + benchmark::DoNotOptimize(input); + benchmark::DoNotOptimize(merge_sort(input)); + } +} + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-attributes" +BENCHMARK(bench)->Range(8, 8 << 10); +BENCHMARK(bench)->Range(8, 8 << 10); +BENCHMARK(bench)->Range(8, 8 << 10); +BENCHMARK(bench)->Range(8, 8 << 10); +#pragma GCC diagnostic pop + +BENCHMARK_MAIN();