-
Notifications
You must be signed in to change notification settings - Fork 2
Timer
nphtan edited this page May 19, 2021
·
2 revisions
Simple timer abstraction.
Header File: Timer.hpp
class Timer
{
public:
using clock_type = std::chrono::high_resolution_clock;
using duration_type = clock_type::duration;
using time_type = std::chrono::time_point< clock_type >;
explicit Timer( bool start_timer = false )
{
if ( start_timer )
start();
}
void start() noexcept { m_start = clock_type::now(); }
duration_type time() const noexcept { return clock_type::now() - m_start; }
private:
time_type m_start;
};
-
clock_type
: The type of clock. -
duration_type
: The time duration type. -
time_type
: The type of the time point.
-
Construct timer objection. Optionally tell timer to start on creation.
explicit Timer( bool start_timer = false )
-
void start() noexcept
Start timer.
-
duration_type time() const noexcept
Get the timers current elapsed time.