-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate_reverse_polish_notation_benchmark.cpp
93 lines (77 loc) · 2.32 KB
/
evaluate_reverse_polish_notation_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
// 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 <string_view>
#include <vector>
#include <catch2/catch_test_macros.hpp>
#include <nanobench.h>
#include <nameof.hpp>
#include "forfun/evaluate_reverse_polish_notation.hpp"
TEST_CASE(
"Evaluate reverse polish notation benchmarking",
"[benchmark][evaluate_reverse_polish_notation]"
)
{
using std::string_view_literals::operator""sv;
using namespace forfun::evaluate_reverse_polish_notation;
using VecConstIter = std::vector<std::string_view>::const_iterator;
std::vector<std::string_view> const tokens{
"149"sv,
"2"sv,
"*"sv,
"61"sv,
"+"sv,
"223"sv,
"+"sv,
"-2"sv,
"+"sv,
"11"sv,
"/"sv,
"71"sv,
"+"sv,
"293"sv,
"*"sv,
"101"sv,
"-"sv,
};
ankerl::nanobench::Bench()
.title("Evaluate reverse polish notation")
.relative(true)
.run(
NAMEOF_RAW(hardened::eval_expression<VecConstIter, VecConstIter>)
.c_str(),
[&tokens]() noexcept(false) {
auto const r{
hardened::eval_expression(tokens.cbegin(), tokens.cend())
};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
.run(
NAMEOF_RAW(unhardened::eval_expression<VecConstIter, VecConstIter>)
.c_str(),
[&tokens]() noexcept(false) {
auto const r{
unhardened::eval_expression(tokens.cbegin(), tokens.cend())
};
ankerl::nanobench::doNotOptimizeAway(r);
}
)
.run(
NAMEOF_RAW(
speed_optimized::eval_expression<VecConstIter, VecConstIter>
)
.c_str(),
[&tokens]() noexcept {
// Ignore Division by zero [core.DivideZero] warning.
#ifndef __clang_analyzer__
auto const r{speed_optimized::eval_expression(
tokens.cbegin(), tokens.cend()
)};
ankerl::nanobench::doNotOptimizeAway(r);
#endif // __clang_analyzer__
}
)
;
}