line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
// Copyright Catch2 Authors |
3
|
|
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. |
4
|
|
|
|
|
|
|
// (See accompanying file LICENSE_1_0.txt or copy at |
5
|
|
|
|
|
|
|
// https://www.boost.org/LICENSE_1_0.txt) |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
// SPDX-License-Identifier: BSL-1.0 |
8
|
|
|
|
|
|
|
// Adapted from donated nonius code. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#ifndef CATCH_ESTIMATE_CLOCK_HPP_INCLUDED |
11
|
|
|
|
|
|
|
#define CATCH_ESTIMATE_CLOCK_HPP_INCLUDED |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#include |
14
|
|
|
|
|
|
|
#include |
15
|
|
|
|
|
|
|
#include |
16
|
|
|
|
|
|
|
#include |
17
|
|
|
|
|
|
|
#include |
18
|
|
|
|
|
|
|
#include |
19
|
|
|
|
|
|
|
#include |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#include |
22
|
|
|
|
|
|
|
#include |
23
|
|
|
|
|
|
|
#include |
24
|
|
|
|
|
|
|
#include |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
namespace Catch { |
27
|
|
|
|
|
|
|
namespace Benchmark { |
28
|
|
|
|
|
|
|
namespace Detail { |
29
|
|
|
|
|
|
|
template |
30
|
0
|
|
|
|
|
|
std::vector resolution(int k) { |
31
|
0
|
|
|
|
|
|
std::vector> times; |
32
|
0
|
0
|
|
|
|
|
times.reserve(k + 1); |
33
|
0
|
0
|
|
|
|
|
std::generate_n(std::back_inserter(times), k + 1, now{}); |
|
|
0
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
std::vector deltas; |
36
|
0
|
0
|
|
|
|
|
deltas.reserve(k); |
37
|
0
|
0
|
|
|
|
|
std::transform(std::next(times.begin()), times.end(), times.begin(), |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
38
|
|
|
|
|
|
|
std::back_inserter(deltas), |
39
|
0
|
|
|
|
|
|
[](TimePoint a, TimePoint b) { return static_cast((a - b).count()); }); |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return deltas; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
const auto warmup_iterations = 10000; |
45
|
|
|
|
|
|
|
const auto warmup_time = std::chrono::milliseconds(100); |
46
|
|
|
|
|
|
|
const auto minimum_ticks = 1000; |
47
|
|
|
|
|
|
|
const auto warmup_seed = 10000; |
48
|
|
|
|
|
|
|
const auto clock_resolution_estimation_time = std::chrono::milliseconds(500); |
49
|
|
|
|
|
|
|
const auto clock_cost_estimation_time_limit = std::chrono::seconds(1); |
50
|
|
|
|
|
|
|
const auto clock_cost_estimation_tick_limit = 100000; |
51
|
|
|
|
|
|
|
const auto clock_cost_estimation_time = std::chrono::milliseconds(10); |
52
|
|
|
|
|
|
|
const auto clock_cost_estimation_iterations = 10000; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
template |
55
|
0
|
|
|
|
|
|
int warmup() { |
56
|
|
|
|
|
|
|
return run_for_at_least(std::chrono::duration_cast>(warmup_time), warmup_seed, &resolution) |
57
|
0
|
0
|
|
|
|
|
.iterations; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
template |
60
|
0
|
|
|
|
|
|
EnvironmentEstimate> estimate_clock_resolution(int iterations) { |
61
|
|
|
|
|
|
|
auto r = run_for_at_least(std::chrono::duration_cast>(clock_resolution_estimation_time), iterations, &resolution) |
62
|
0
|
0
|
|
|
|
|
.result; |
63
|
|
|
|
|
|
|
return { |
64
|
0
|
0
|
|
|
|
|
FloatDuration(mean(r.begin(), r.end())), |
65
|
0
|
|
|
|
|
|
classify_outliers(r.begin(), r.end()), |
66
|
0
|
0
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
template |
69
|
0
|
|
|
|
|
|
EnvironmentEstimate> estimate_clock_cost(FloatDuration resolution) { |
70
|
0
|
|
|
|
|
|
auto time_limit = (std::min)( |
71
|
|
|
|
|
|
|
resolution * clock_cost_estimation_tick_limit, |
72
|
0
|
|
|
|
|
|
FloatDuration(clock_cost_estimation_time_limit)); |
73
|
0
|
|
|
|
|
|
auto time_clock = [](int k) { |
74
|
0
|
|
|
|
|
|
return Detail::measure([k] { |
75
|
0
|
0
|
|
|
|
|
for (int i = 0; i < k; ++i) { |
76
|
0
|
|
|
|
|
|
volatile auto ignored = Clock::now(); |
77
|
0
|
|
|
|
|
|
(void)ignored; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
}).elapsed; |
80
|
0
|
0
|
|
|
|
|
}; |
81
|
0
|
0
|
|
|
|
|
time_clock(1); |
82
|
0
|
|
|
|
|
|
int iters = clock_cost_estimation_iterations; |
83
|
0
|
0
|
|
|
|
|
auto&& r = run_for_at_least(std::chrono::duration_cast>(clock_cost_estimation_time), iters, time_clock); |
84
|
0
|
|
|
|
|
|
std::vector times; |
85
|
0
|
|
|
|
|
|
int nsamples = static_cast(std::ceil(time_limit / r.elapsed)); |
86
|
0
|
0
|
|
|
|
|
times.reserve(nsamples); |
87
|
0
|
0
|
|
|
|
|
std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] { |
|
|
0
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return static_cast((time_clock(r.iterations) / r.iterations).count()); |
89
|
0
|
|
|
|
|
|
}); |
90
|
|
|
|
|
|
|
return { |
91
|
0
|
0
|
|
|
|
|
FloatDuration(mean(times.begin(), times.end())), |
92
|
0
|
|
|
|
|
|
classify_outliers(times.begin(), times.end()), |
93
|
0
|
0
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
template |
97
|
0
|
|
|
|
|
|
Environment> measure_environment() { |
98
|
|
|
|
|
|
|
#if defined(__clang__) |
99
|
|
|
|
|
|
|
# pragma clang diagnostic push |
100
|
|
|
|
|
|
|
# pragma clang diagnostic ignored "-Wexit-time-destructors" |
101
|
|
|
|
|
|
|
#endif |
102
|
0
|
0
|
|
|
|
|
static Catch::Detail::unique_ptr>> env; |
|
|
0
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#if defined(__clang__) |
104
|
|
|
|
|
|
|
# pragma clang diagnostic pop |
105
|
|
|
|
|
|
|
#endif |
106
|
0
|
0
|
|
|
|
|
if (env) { |
107
|
0
|
|
|
|
|
|
return *env; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
auto iters = Detail::warmup(); |
111
|
0
|
0
|
|
|
|
|
auto resolution = Detail::estimate_clock_resolution(iters); |
112
|
0
|
0
|
|
|
|
|
auto cost = Detail::estimate_clock_cost(resolution.mean); |
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
env = Catch::Detail::make_unique>>( Environment>{resolution, cost} ); |
115
|
0
|
|
|
|
|
|
return *env; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} // namespace Detail |
118
|
|
|
|
|
|
|
} // namespace Benchmark |
119
|
|
|
|
|
|
|
} // namespace Catch |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#endif // CATCH_ESTIMATE_CLOCK_HPP_INCLUDED |