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_CHRONOMETER_HPP_INCLUDED |
11
|
|
|
|
|
|
|
#define CATCH_CHRONOMETER_HPP_INCLUDED |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#include |
14
|
|
|
|
|
|
|
#include |
15
|
|
|
|
|
|
|
#include |
16
|
|
|
|
|
|
|
#include |
17
|
|
|
|
|
|
|
#include |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
namespace Catch { |
20
|
|
|
|
|
|
|
namespace Benchmark { |
21
|
|
|
|
|
|
|
namespace Detail { |
22
|
|
|
|
|
|
|
struct ChronometerConcept { |
23
|
|
|
|
|
|
|
virtual void start() = 0; |
24
|
|
|
|
|
|
|
virtual void finish() = 0; |
25
|
|
|
|
|
|
|
virtual ~ChronometerConcept(); // = default; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
ChronometerConcept() = default; |
28
|
|
|
|
|
|
|
ChronometerConcept(ChronometerConcept const&) = default; |
29
|
|
|
|
|
|
|
ChronometerConcept& operator=(ChronometerConcept const&) = default; |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
template |
32
|
0
|
0
|
|
|
|
|
struct ChronometerModel final : public ChronometerConcept { |
33
|
0
|
|
|
|
|
|
void start() override { started = Clock::now(); } |
34
|
0
|
|
|
|
|
|
void finish() override { finished = Clock::now(); } |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
ClockDuration elapsed() const { return finished - started; } |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
TimePoint started; |
39
|
|
|
|
|
|
|
TimePoint finished; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} // namespace Detail |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
struct Chronometer { |
44
|
|
|
|
|
|
|
public: |
45
|
|
|
|
|
|
|
template |
46
|
0
|
0
|
|
|
|
|
void measure(Fun&& fun) { measure(CATCH_FORWARD(fun), is_callable()); } |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
int runs() const { return repeats; } |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
Chronometer(Detail::ChronometerConcept& meter, int repeats_) |
51
|
|
|
|
|
|
|
: impl(&meter) |
52
|
0
|
|
|
|
|
|
, repeats(repeats_) {} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
private: |
55
|
|
|
|
|
|
|
template |
56
|
0
|
|
|
|
|
|
void measure(Fun&& fun, std::false_type) { |
57
|
0
|
0
|
|
|
|
|
measure([&fun](int) { return fun(); }, std::true_type()); |
58
|
0
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
template |
61
|
0
|
|
|
|
|
|
void measure(Fun&& fun, std::true_type) { |
62
|
0
|
|
|
|
|
|
Detail::optimizer_barrier(); |
63
|
0
|
|
|
|
|
|
impl->start(); |
64
|
0
|
0
|
|
|
|
|
for (int i = 0; i < repeats; ++i) invoke_deoptimized(fun, i); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
impl->finish(); |
66
|
0
|
|
|
|
|
|
Detail::optimizer_barrier(); |
67
|
0
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Detail::ChronometerConcept* impl; |
70
|
|
|
|
|
|
|
int repeats; |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
} // namespace Benchmark |
73
|
|
|
|
|
|
|
} // namespace Catch |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#endif // CATCH_CHRONOMETER_HPP_INCLUDED |