-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaximum_subarray_benchmark.cpp
60 lines (46 loc) · 1.63 KB
/
maximum_subarray_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
// 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/maximum_subarray.hpp"
TEST_CASE("Maximum subarray benchmarking", "[benchmark][maximum_subarray]")
{
using namespace forfun::maximum_subarray;
std::array const input{0, 52, -100, 0, 1, 30, -6, 33};
using ConstIter = decltype(input)::const_iterator;
ankerl::nanobench::Bench()
.title("Maximum subarray")
.relative(true)
.run(
NAMEOF_RAW(brute_force::max_sum<ConstIter, ConstIter>).c_str(),
[&input]() noexcept {
auto const volatile r{
brute_force::max_sum(input.cbegin(), input.cend())
};
ankerl::nanobench::doNotOptimizeAway(&r);
}
)
.run(
NAMEOF_RAW(recursive::max_sum<ConstIter, ConstIter>).c_str(),
[&input]() noexcept {
auto const volatile r{
recursive::max_sum(input.cbegin(), input.cend())
};
ankerl::nanobench::doNotOptimizeAway(&r);
}
)
.run(
NAMEOF_RAW(streaming::max_sum<ConstIter, ConstIter>).c_str(),
[&input]() noexcept {
auto const volatile r{
streaming::max_sum(input.cbegin(), input.cend())
};
ankerl::nanobench::doNotOptimizeAway(&r);
}
)
;
}