-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst_missing_positive_benchmark.cpp
90 lines (73 loc) · 2.92 KB
/
first_missing_positive_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// 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 <tuple>
#include <catch2/catch_test_macros.hpp>
#include <nanobench.h>
#include <nameof.hpp>
#include "forfun/first_missing_positive.hpp"
TEST_CASE(
"Lowest missing positive integer benchmarking",
"[benchmark][first_missing_positive]"
)
{
using namespace forfun::first_missing_positive;
using ContainerType = std::array<int, 128U>;
using Itr = ContainerType::iterator;
ankerl::nanobench::Bench()
.title("Lowest missing positive integer")
.relative(true)
.run(
NAMEOF_RAW(base::lowest_missing<Itr, Itr>).c_str(),
[]() noexcept {
std::array nums{
// clang-format off
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
0, 0, 0, 0, 0, 0, 0, 0,
// clang-format on
};
static_assert(nums.size() == std::tuple_size_v<ContainerType>);
auto const r{base::lowest_missing(nums.begin(), nums.end())};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
.run(
NAMEOF_RAW(fast::lowest_missing<Itr, Itr>).c_str(),
[]() noexcept {
std::array nums{
// clang-format off
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
9, 8, 7, 6, 5, 4, 3, 2, 1, -1,
0, 0, 0, 0, 0, 0, 0, 0,
// clang-format on
};
static_assert(nums.size() == std::tuple_size_v<ContainerType>);
auto const r{fast::lowest_missing(nums.begin(), nums.end())};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
;
}