-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnumeric_bench.cpp
41 lines (30 loc) · 1.19 KB
/
numeric_bench.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
// Copyright (C) 2023 Adam Lugowski. All rights reserved.
// Use of this source code is governed by:
// the BSD 2-clause license, the MIT license, or at your choosing the BSL-1.0 license found in the LICENSE.*.txt files.
// SPDX-License-Identifier: BSD-2-Clause OR MIT OR BSL-1.0
#include <numeric>
#include <vector>
#include <benchmark/benchmark.h>
#include <poolstl/numeric>
#include "utils.hpp"
////////////////////////////////
template <class ExecPolicy>
void reduce(benchmark::State& state) {
auto values = iota_vector(arr_length);
for ([[maybe_unused]] auto _ : state) {
int64_t sum = 0;
if constexpr (is_policy<ExecPolicy>::value) {
sum = std::reduce(policy<ExecPolicy>::get(), values.begin(), values.end());
} else {
sum = std::reduce(values.begin(), values.end());
}
benchmark::DoNotOptimize(sum);
benchmark::ClobberMemory();
}
}
BENCHMARK(reduce<seq>)->Name("reduce()")->UseRealTime();
BENCHMARK(reduce<poolstl_par>)->Name("reduce(poolstl::par)")->UseRealTime();
#ifdef POOLSTL_BENCH_STD_PAR
BENCHMARK(reduce<std_par>)->Name("reduce(std::execution::par)")->UseRealTime();
#endif
////////////////////////////////