-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubsets_benchmark.cpp
More file actions
92 lines (76 loc) · 2.72 KB
/
subsets_benchmark.cpp
File metadata and controls
92 lines (76 loc) · 2.72 KB
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
// 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 <cstddef>
#include <format>
#include <vector>
#include <catch2/catch_test_macros.hpp>
#include <nanobench.h>
#include <nameof.hpp>
#include "forfun/subsets.hpp"
TEST_CASE("Subsets benchmarking", "[benchmark][subsets]")
{
using namespace forfun::subsets;
static constexpr std::size_t const num_elements{4};
using ElementType = int;
using ConstIter = std::vector<ElementType>::const_iterator;
using ElementDefaultAllocator = std::vector<ElementType>::allocator_type;
using SubsetDefaultAllocator = std::vector<
std::vector<ElementType, ElementDefaultAllocator>>::allocator_type;
using ElementAllocatorFactory
= ElementInPlaceAllocatorFactory<ElementType, num_elements>;
using SubsetAllocatorFactory = SubsetInPlaceAllocatorFactory<
ElementType,
ElementAllocatorFactory::allocator_type,
num_elements>;
std::vector const elements{23, 29, 31, 37};
ankerl::nanobench::Bench()
.title("Subsets")
.relative(true)
.run(
// clang-format off
NAMEOF_RAW(
recursive::explode_subsets<
ConstIter,
ConstIter,
ElementDefaultAllocator,
SubsetDefaultAllocator>
)
.c_str(),
// clang-format on
[&elements] -> void {
auto const volatile r{recursive::explode_subsets(
elements.cbegin(), elements.cend()
)};
ankerl::nanobench::doNotOptimizeAway(&r);
}
)
.run(
std::format(
"{} preallocated",
// clang-format off
NAMEOF_RAW(
recursive::explode_subsets<
ConstIter,
ConstIter,
ElementAllocatorFactory,
SubsetAllocatorFactory>
)
.c_str()
// clang-format on
),
[&elements] -> void {
SubsetAllocatorFactory const subset_allocator_factory{};
ElementAllocatorFactory const element_allocator_factory{};
auto const volatile r{recursive::explode_subsets(
elements.cbegin(),
elements.cend(),
subset_allocator_factory.allocator(),
element_allocator_factory.allocator()
)};
ankerl::nanobench::doNotOptimizeAway(&r);
}
)
;
}