-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfibonacci_benchmark.cpp
47 lines (32 loc) · 1.04 KB
/
fibonacci_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
// 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/fibonacci.hpp"
TEST_CASE("Fibonacci number benchmarking", "[benchmark][fibonacci]")
{
using namespace forfun::fibonacci;
static constexpr std::uint_fast32_t const n{7U};
ankerl::nanobench::Bench()
.title("Fibonacci number")
.relative(true)
.run(
NAMEOF_RAW(iterative::fib<std::uint_fast32_t>).c_str(),
[]() noexcept {
auto const r{iterative::fib(n)};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
.run(
NAMEOF_RAW(recursive::fib<std::uint_fast32_t>).c_str(),
[]() noexcept {
auto const r{recursive::fib(n)};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
;
}