-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeeting_rooms_benchmark.cpp
103 lines (81 loc) · 2.61 KB
/
meeting_rooms_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
91
92
93
94
95
96
97
98
99
100
101
102
103
// 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 <vector>
#include <catch2/catch_test_macros.hpp>
#include <nanobench.h>
#include <nameof.hpp>
#include "forfun/meeting_rooms.hpp"
TEST_CASE("Meeting rooms benchmarking", "[benchmark][meeting_rooms]")
{
using namespace forfun::meeting_rooms;
std::vector<interval> const intervals{
{.start = 0, .end = 1},
{.start = 1, .end = 2},
{.start = 2, .end = 3},
{.start = 3, .end = 4},
{.start = 4, .end = 5},
{.start = 5, .end = 6},
{.start = 6, .end = 7},
{.start = 7, .end = 8},
{.start = 8, .end = 9},
{.start = 9, .end = 10},
{.start = 10, .end = 11},
{.start = 11, .end = 12},
{.start = 12, .end = 13},
{.start = 13, .end = 14},
{.start = 14, .end = 15},
{.start = 15, .end = 16},
};
using Iter = decltype(intervals)::const_iterator;
ankerl::nanobench::Bench()
.title("Meeting rooms")
.relative(true)
.run(
NAMEOF_RAW(can_attend<Iter, Iter>).c_str(),
[&intervals]() noexcept {
auto const volatile r{
can_attend(intervals.cbegin(), intervals.cend())
};
ankerl::nanobench::doNotOptimizeAway(&r);
}
)
;
}
TEST_CASE("Meeting rooms 2 benchmarking", "[benchmark][meeting_rooms_2]")
{
using namespace forfun::meeting_rooms;
std::vector<interval> const intervals{
{.start = 0, .end = 1},
{.start = 1, .end = 2},
{.start = 2, .end = 3},
{.start = 3, .end = 4},
{.start = 4, .end = 5},
{.start = 5, .end = 6},
{.start = 6, .end = 7},
{.start = 7, .end = 8},
{.start = 8, .end = 9},
{.start = 9, .end = 10},
{.start = 10, .end = 11},
{.start = 11, .end = 12},
{.start = 12, .end = 13},
{.start = 13, .end = 14},
{.start = 14, .end = 15},
{.start = 15, .end = 16},
};
using Iter = decltype(intervals)::const_iterator;
ankerl::nanobench::Bench()
.title("Meeting rooms 2")
.relative(true)
.run(
NAMEOF_RAW(min_chronotopes<Iter, Iter>).c_str(),
[&intervals]() noexcept {
auto const volatile r{
min_chronotopes(intervals.cbegin(), intervals.cend())
};
ankerl::nanobench::doNotOptimizeAway(&r);
}
)
;
}