-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtower_of_hanoi_benchmark.cpp
48 lines (34 loc) · 1.21 KB
/
tower_of_hanoi_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
// 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 <cstddef>
#include <catch2/catch_test_macros.hpp>
#include <nanobench.h>
#include <nameof.hpp>
#include "forfun/tower_of_hanoi.hpp"
TEST_CASE("Tower of Hanoi benchmarking", "[benchmark][tower_of_hanoi]")
{
using namespace forfun::tower_of_hanoi;
using Rod = int;
using Monk = decltype([](Rod&, Rod&) noexcept -> void {});
ankerl::nanobench::Bench()
.title("Tower of Hanoi")
.relative(true)
.run(
NAMEOF_RAW(recursive::toh<Rod, Monk, std::size_t>).c_str(),
[]() noexcept {
static constexpr std::size_t const num_disks{4U};
// NOLINTBEGIN(misc-const-correctness)
Rod src{};
Rod des{};
Rod aux{};
// NOLINTEND(misc-const-correctness)
forfun::tower_of_hanoi::recursive::toh(
src, des, aux, [](Rod&, Rod&) noexcept -> void {}, num_disks
);
ankerl::nanobench::doNotOptimizeAway(des);
}
)
;
}