-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactorial_benchmark.cpp
57 lines (41 loc) · 1.42 KB
/
factorial_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
// 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 <cstdint>
#include <catch2/catch_test_macros.hpp>
#include <nanobench.h>
#include <nameof.hpp>
#include "forfun/factorial.hpp"
TEST_CASE("Factorial benchmarking", "[benchmark][factorial]")
{
using namespace forfun::factorial;
ankerl::nanobench::Bench()
.title("Factorial")
.relative(true)
.run(
NAMEOF_RAW(iterative::factorial<std::uint64_t>).c_str(),
[]() noexcept {
auto const volatile n{std::uint64_t{20U}};
auto const r{iterative::factorial(n)};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
.run(
NAMEOF_RAW(recursive::factorial<std::uint64_t>).c_str(),
[]() noexcept {
auto const volatile n{std::uint64_t{20U}};
auto const r{recursive::factorial(n)};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
.run(
NAMEOF_RAW(stl_functional::factorial<std::uint64_t>).c_str(),
[]() noexcept {
auto const volatile n{std::uint64_t{20U}};
auto const r{stl_functional::factorial(n)};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
;
}