delpi
0.0.1
DElta-complete LP solver
Toggle main menu visibility
Loading...
Searching...
No Matches
Timer.h
1
8
#pragma once
9
10
#include <chrono>
11
#include <cstdint>
12
#include <ratio>
13
#include <type_traits>
14
15
namespace
delpi
{
16
17
// Forward declaration. Found later in this file
18
struct
user_clock
;
19
25
template
<
typename
T>
26
class
TimerBase {
27
public
:
28
using
clock = T;
29
typedef
typename
clock::duration duration;
30
typedef
typename
clock::time_point time_point;
31
33
TimerBase();
34
40
void
Start
();
41
47
void
Pause
();
48
54
void
Resume
();
55
57
[[nodiscard]]
bool
is_running()
const
;
59
[[nodiscard]] duration elapsed()
const
;
61
[[nodiscard]] std::chrono::duration<double>::rep seconds()
const
;
62
63
TimerBase<T> &operator+=(
const
TimerBase<T> &other);
64
TimerBase<T> operator+(
const
TimerBase<T> &other)
const
;
65
66
protected
:
68
[[nodiscard]] time_point now()
const
{
return
clock::now(); }
69
70
private
:
71
bool
running_
{
false
};
72
time_point
last_start_
{};
73
duration
elapsed_
{};
74
};
75
76
template
<
typename
T>
77
TimerBase<T> &TimerBase<T>::operator+=(
const
TimerBase<T> &other) {
78
elapsed_ += other.elapsed();
79
return
*
this
;
80
}
81
82
template
<
typename
T>
83
TimerBase<T>
TimerBase<T>::operator+(
const
TimerBase<T>
&other)
const
{
84
TimerBase<T>
result = *
this
;
85
result += other;
86
return
result;
87
}
88
89
// Use high_resolution clock if it's steady, otherwise use steady_clock.
90
using
chosen_steady_clock = std::conditional_t<std::chrono::high_resolution_clock::is_steady,
91
std::chrono::high_resolution_clock, std::chrono::steady_clock>;
92
93
extern
template
class
TimerBase<chosen_steady_clock>
;
95
class
Timer
:
public
TimerBase<chosen_steady_clock> {};
96
101
struct
user_clock
{
102
typedef
uint64_t rep;
103
typedef
std::micro period;
104
typedef
std::chrono::duration<rep, period> duration;
105
typedef
std::chrono::time_point<user_clock> time_point;
106
const
bool
is_steady =
false
;
// Not sure how this should be interpreted here
107
static
time_point now();
108
};
109
110
extern
template
class
TimerBase<user_clock>
;
112
class
UserTimer
:
public
TimerBase<user_clock> {};
113
132
class
TimerGuard
{
133
public
:
144
TimerGuard
(
Timer
*timer,
bool
enabled,
bool
start_timer =
true
);
145
146
TimerGuard
(
const
TimerGuard
&) =
delete
;
147
TimerGuard
(
TimerGuard
&&) =
delete
;
148
TimerGuard
&operator=(
const
TimerGuard
&) =
delete
;
149
TimerGuard
&operator=(
TimerGuard
&&) =
delete
;
150
155
~TimerGuard
();
156
158
void
Pause
();
159
161
void
Resume
();
162
163
private
:
164
Timer
*
const
timer_
;
165
const
bool
enabled_
{
false
};
166
};
167
168
}
// namespace delpi
delpi::TimerBase
Simple timer class to evaluate the performance of the software.
Definition
Timer.h:26
delpi::TimerBase::Resume
void Resume()
Resume the timer.
Definition
Timer.cpp:38
delpi::TimerBase::elapsed_
duration elapsed_
Elapsed time so far. This doesn't include the current fragment if it is running.
Definition
Timer.h:73
delpi::TimerBase::Pause
void Pause()
Pause the timer.
Definition
Timer.cpp:30
delpi::TimerBase::Start
void Start()
Start the timer.
Definition
Timer.cpp:22
delpi::TimerBase::last_start_
time_point last_start_
Last time_point when the timer is started or resumed.
Definition
Timer.h:72
delpi::TimerBase::running_
bool running_
Whether the timer is running or not.
Definition
Timer.h:71
delpi::TimerGuard::Pause
void Pause()
Pause the guarded timer object.
Definition
Timer.cpp:83
delpi::TimerGuard::enabled_
const bool enabled_
Whether the timer is enabled.
Definition
Timer.h:165
delpi::TimerGuard::TimerGuard
TimerGuard(Timer *timer, bool enabled, bool start_timer=true)
Construct a new TimeGuard object.
Definition
Timer.cpp:74
delpi::TimerGuard::Resume
void Resume()
Resume the guarded timer object.
Definition
Timer.cpp:87
delpi::TimerGuard::timer_
Timer *const timer_
The timer to be guarded.
Definition
Timer.h:164
delpi::Timer
Timer class using the a steady clock.
Definition
Timer.h:95
delpi::UserTimer
Timer class using the user_clock.
Definition
Timer.h:112
delpi
Global namespace for the delpi library.
delpi::user_clock
Structure that will hold the user clock data.
Definition
Timer.h:101
delpi
util
Timer.h
Generated by
1.17.0