31 #ifndef SOLIDUTILS_INCLUDE_TIMER_HPP 32 #define SOLIDUTILS_INCLUDE_TIMER_HPP 90 std::chrono::high_resolution_clock::time_point time =
91 std::chrono::high_resolution_clock::now();
92 size_t const ticks = \
93 static_cast<
size_t>(time.time_since_epoch().count());
94 double constexpr SECONDS_PER_TICK = \
95 static_cast<
double>(std::chrono::system_clock::period::num) / \
96 static_cast<double>(std::chrono::system_clock::period::den);
97 double const seconds = ticks * SECONDS_PER_TICK;
115 Timer *
const parent) :
129 m_parent(
scope.m_parent),
130 m_start(
scope.m_start)
132 scope.m_parent =
nullptr;
142 Scope const & other) =
delete;
152 Scope const & other) =
delete;
161 if (m_parent !=
nullptr) {
162 m_parent->
add(stop - m_start);
189 if (m_scope.get() !=
nullptr) {
190 throw std::runtime_error(
191 "Cannot start scope for already running timer.");
202 if (m_scope.get() !=
nullptr) {
203 throw std::runtime_error(
"Cannot start already running timer.");
206 m_scope.reset(
new Scope(
this));
214 if (m_scope.get() ==
nullptr) {
215 throw std::runtime_error(
"Cannot stop non-running timer.");
219 m_scope.reset(
nullptr);
229 if (m_scope.get() !=
nullptr) {
230 throw std::runtime_error(
"Cannot poll running timer.");
244 m_duration += duration;
249 std::unique_ptr<Scope> m_scope;
This class is used to perform wall timings of varius tasks. It provides means to meanually start and ...
Definition: Timer.hpp:78
Scope(Scope &&scope)
Move once Scope to this Scope.
Definition: Timer.hpp:127
This class provides a means of timing a scoped region. It begins timing when it is created...
Definition: Timer.hpp:106
Scope & operator=(Scope const &other)=delete
Deleted assignment operator.
Scope(Timer *const parent)
Create a new Scope from the given timer.
Definition: Timer.hpp:114
Scope scope()
Start a new timed scope. The duration from when the Scope object is created.
Definition: Timer.hpp:187
static double now()
Get a double representing the current time in seconds. This is an arbitrary value by itself...
Definition: Timer.hpp:88
double poll() const
Get the elapsed number of seconds on the timer.
Definition: Timer.hpp:227
~Scope()
Destroy this timer Scope.
Definition: Timer.hpp:157
Timer()
Creat a new timer.
Definition: Timer.hpp:174
void stop()
Stop the timer.
Definition: Timer.hpp:212
void add(double duration)
Add some amount of time to the timer.
Definition: Timer.hpp:241
void start()
Start or continue the timer.
Definition: Timer.hpp:200