-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.hpp
85 lines (66 loc) · 2.1 KB
/
utils.hpp
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
// 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
#ifndef POOLSTL_BENCH_UTILS_HPP
#define POOLSTL_BENCH_UTILS_HPP
#include <algorithm>
#include <random>
#ifdef POOLSTL_BENCH_STD_PAR
// Benchmarking std::execution::par requested. Verify it is available.
#if __cplusplus >= 201603L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201603L)
#if __has_include(<execution>)
#include <execution>
#endif
#endif
#if !defined(__cpp_lib_parallel_algorithm)
// native parallel algorithms not available
#undef POOLSTL_BENCH_STD_PAR
#endif
#endif
#include <numeric>
#include <utility>
#include <vector>
#include <benchmark/benchmark.h>
#include <poolstl/algorithm>
#include <poolstl/numeric>
constexpr long long arr_length = 100'000'000;
struct seq {};
struct poolstl_par {};
struct std_par {};
template <typename T> struct is_policy : std::true_type {};
template <> struct is_policy<seq> : std::false_type {};
template <typename T> struct policy {};
template <> struct policy<poolstl_par> {
constexpr static poolstl::execution::parallel_policy get() {
return poolstl::execution::par;
};
};
template <> struct policy<poolstl::execution::par_pool> {
static poolstl::execution::par_pool get() {
static task_thread_pool::task_thread_pool pool;
return poolstl::execution::par_pool(pool);
};
};
#ifdef POOLSTL_BENCH_STD_PAR
template <> struct policy<std_par> {
constexpr static const std::execution::parallel_policy& get() {
return std::execution::par;
};
};
#endif
template <typename T=int>
std::vector<T> iota_vector(size_t size, T init=0) {
std::vector<T> ret(size);
std::iota(ret.begin(), ret.end(), init);
return ret;
}
template <typename T=int>
std::vector<T> random_vector(size_t size, T init=0) {
std::vector<T> ret = iota_vector<T>(size, T{});
std::mt19937 g(1);
std::shuffle(ret.begin(), ret.end(), g);
return ret;
}
void slow();
#endif