-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsub_array_sums_benchmark.cpp
54 lines (41 loc) · 1.31 KB
/
sub_array_sums_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
// 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 <catch2/catch_test_macros.hpp>
#include <nanobench.h>
#include <nameof.hpp>
#include "forfun/sub_array_sums.hpp"
TEST_CASE(
"Sum of all subarrays of size K benchmarking", "[benchmark][sub_array_sums]"
)
{
using namespace forfun::sub_array_sums;
constexpr std::array const numbers{
// clang-format off
1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8,
// clang-format on
};
std::array<int, 8U> sums{};
ankerl::nanobench::Bench()
.title("Sum of all subarrays of size K")
.relative(true)
.run(
NAMEOF_RAW(sum_each<std::array<int, 64U>, std::array<int, 8U>>)
.c_str(),
[&numbers, &sums]() noexcept {
decltype(numbers)::size_type const volatile sub_size{8U};
sum_each(numbers, sums, sub_size);
ankerl::nanobench::doNotOptimizeAway(sums);
}
)
;
}