-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbench.hpp
64 lines (51 loc) · 1.37 KB
/
bench.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
// ====================================================================
// This file is part of Polylogarithm.
//
// Polylogarithm is licenced under the MIT License.
// ====================================================================
#pragma once
#include "stopwatch.hpp"
#include <algorithm>
#include <complex>
#include <random>
#include <vector>
namespace polylogarithm {
namespace bench {
template <class T>
std::vector<T> generate_random_scalars(int n, T start, T stop)
{
static std::minstd_rand gen;
std::uniform_real_distribution<T> dist(start, stop);
std::vector<T> v(n);
std::generate(begin(v), end(v),
[&dist](){ return dist(gen); });
return v;
}
template <class T>
std::vector<std::complex<T>> generate_random_complexes(
int n, T start, T stop)
{
const auto reals = generate_random_scalars<T>(n, start, stop);
const auto imags = generate_random_scalars<T>(n, start, stop);
std::vector<std::complex<T>> v(n);
for (int i = 0; i < n; i++) {
v[i] = std::complex<T>(reals[i], imags[i]);
}
return v;
}
template <class T>
inline void do_not_optimize(const T& value)
{
asm volatile("" : : "r,m"(value) : "memory");
}
template <class F>
double time_in_seconds(F&& f)
{
polylogarithm::Stopwatch sw;
sw.start();
f();
sw.stop();
return sw.get_time_in_seconds();
}
} // namespace bench
} // namespace polylogarithm