-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct_except_self_benchmark.cpp
81 lines (66 loc) · 2.12 KB
/
product_except_self_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
// 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 <array>
#include <cstdint>
#include <type_traits>
#include <catch2/catch_test_macros.hpp>
#include <nanobench.h>
#include <nameof.hpp>
#include "forfun/product_except_self.hpp"
TEST_CASE(
"Product of array except self benchmarking",
"[benchmark][product_except_self]"
)
{
using namespace forfun::product_except_self;
static constexpr std::array<std::uint64_t, 16> const input{
1U,
2U,
3U,
4U,
5U,
6U,
7U,
8U,
9U,
10U,
11U,
12U,
13U,
14U,
15U,
0U,
};
using ConstItr = decltype(input)::const_iterator;
using Itr = std::remove_const_t<decltype(input)>::iterator;
ankerl::nanobench::Bench()
.title("Product of array except self")
.relative(true)
.run(
NAMEOF_RAW(alg1::product_except_self<ConstItr, ConstItr, Itr, Itr>)
.c_str(),
[]() noexcept {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
std::array<std::uint64_t, 16U> result /*[[indeterminate]]*/;
forfun::product_except_self::alg1::product_except_self(
input.cbegin(), input.cend(), result.begin(), result.end()
);
ankerl::nanobench::doNotOptimizeAway(result);
}
)
.run(
NAMEOF_RAW(alg2::product_except_self<ConstItr, ConstItr, Itr, Itr>)
.c_str(),
[]() noexcept {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
std::array<std::uint64_t, 16U> result /*[[indeterminate]]*/;
forfun::product_except_self::alg2::product_except_self(
input.cbegin(), input.cend(), result.begin(), result.end()
);
ankerl::nanobench::doNotOptimizeAway(result);
}
)
;
}