-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmajority_element_benchmark.cpp
42 lines (31 loc) · 1.2 KB
/
majority_element_benchmark.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) Omar Boukli-Hacene. All rights reserved.
// Distributed under an MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT
#include <array>
#include <catch2/catch_test_macros.hpp>
#include <nanobench.h>
#include <nameof.hpp>
#include "forfun/majority_element.hpp"
TEST_CASE("Boyer-Moore majority benchmarking", "[benchmark][majority_element]")
{
using namespace forfun::majority_element;
ankerl::nanobench::Bench()
.title("Boyer-Moore majority")
.relative(true)
.run(
NAMEOF_RAW(majority_element<std::array<int, 64U>>).c_str(),
[]() noexcept {
static constexpr std::array const elements{
5, 7, 7, 7, 7, 5, 5, 7, 5, 5, 5, 7, 7, 5, 5, 5,
5, 7, 7, 7, 7, 5, 5, 7, 5, 5, 5, 7, 7, 5, 5, 5,
5, 7, 7, 7, 7, 5, 5, 7, 5, 5, 5, 7, 7, 5, 5, 5,
5, 7, 7, 7, 7, 5, 5, 7, 5, 5, 5, 7, 7, 5, 5, 5,
};
using ConstItr = decltype(elements)::const_iterator;
ConstItr r{majority_element(elements)};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
;
}