-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalindromic_number_benchmark.cpp
53 lines (38 loc) · 1.34 KB
/
palindromic_number_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
// 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 <limits>
#include <catch2/catch_test_macros.hpp>
#include <nanobench.h>
#include <nameof.hpp>
#include "forfun/palindromic_number.hpp"
TEST_CASE("Palindromic number benchmarking", "[benchmark][palindromic_number]")
{
using namespace forfun::palindromic_number;
static constexpr int const palindromic_num{1234554321};
static_assert(
(palindromic_num >= decltype(palindromic_num){0})
and (palindromic_num <= std::numeric_limits<decltype(palindromic_num)>::max())
);
ankerl::nanobench::Bench()
.title("Palindromic number")
.relative(true)
.run(
NAMEOF_RAW(fast::is_palindrome<int>).c_str(),
[]() noexcept {
auto const volatile p{palindromic_num};
auto const r{fast::is_palindrome(p)};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
.run(
NAMEOF_RAW(stl::is_palindrome).c_str(),
[]() noexcept {
auto const volatile p{palindromic_num};
auto const r{stl::is_palindrome(p)};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
;
}