3#include <Common/primitive_type.h>
16 using Clock = std::chrono::steady_clock;
58 template<
typename NumberType = u
int64>
61 template<
typename NumberType = u
int64>
64 template<
typename NumberType = u
int64>
67 template<
typename NumberType = u
int64>
70 template<
typename NumberType = u
int64>
73 template<
typename NumberType = u
int64>
76 template<
typename NumberType = u
int64>
79 template<
typename NumberType = u
int64>
84 template<
typename TimeRepresentation,
typename TimePeriod>
87 Clock::time_point m_timeMark;
97 m_timeMark = Clock::now();
98 m_totalDuration = DefaultTimeUnit::zero();
105 m_timeMark = Clock::now();
112 m_totalDuration += Clock::now() - m_timeMark;
119 const auto currentTime = Clock::now();
120 const auto lapDuration = currentTime - m_timeMark;
122 m_timeMark = currentTime;
123 m_totalDuration += lapDuration;
130 const auto currentTime = Clock::now();
131 const auto lapDuration = currentTime - m_timeMark;
138 return m_totalDuration;
141template<
typename NumberType>
144 return castToNumber<NumberType, std::ratio<1>>(
markLap());
147template<
typename NumberType>
150 return castToNumber<NumberType, std::milli>(
markLap());
153template<
typename NumberType>
156 return castToNumber<NumberType, std::micro>(
markLap());
159template<
typename NumberType>
162 return castToNumber<NumberType, std::nano>(
markLap());
165template<
typename NumberType>
168 return castToNumber<NumberType, std::ratio<1>>(
getDelta());
171template<
typename NumberType>
174 return castToNumber<NumberType, std::milli>(
getDelta());
177template<
typename NumberType>
180 return castToNumber<NumberType, std::micro>(
getDelta());
183template<
typename NumberType>
186 return castToNumber<NumberType, std::nano>(
getDelta());
189template<
typename TimeRepresentation,
typename TimePeriod>
190inline TimeRepresentation Timer::castToNumber(
const DefaultTimeUnit duration)
192 using DstDuration = std::chrono::duration<TimeRepresentation, TimePeriod>;
196 return std::chrono::duration_cast<DstDuration>(duration).count();
A timer. Measures relative time (not wall clock).
Definition Timer.h:14
NumberType markLapUs()
Definition Timer.h:154
NumberType getDeltaNs() const
Definition Timer.h:184
Timer()
Definition Timer.h:91
Clock::duration DefaultTimeUnit
Definition Timer.h:17
NumberType getDeltaMs() const
Definition Timer.h:172
Timer & accumulatedStart()
Effectively resumes the timer. Start the timer by continuing last result from stop().
Definition Timer.h:103
Timer & stop()
Stop the timer and record elapsed time.
Definition Timer.h:110
DefaultTimeUnit getDelta() const
Get the time elapsed between start() and stop(). Possibly accumulated. Result may be accumulated if a...
Definition Timer.h:136
NumberType markLapS()
Variants that return time in plain number with different units and types. As casting a numeric value ...
Definition Timer.h:142
NumberType markLapNs()
Definition Timer.h:160
NumberType markLapMs()
Definition Timer.h:148
DefaultTimeUnit peekLap() const
Get the time elapsed from last call to markLap(). Get the result of markLap() as if it was called,...
Definition Timer.h:128
NumberType getDeltaS() const
Definition Timer.h:166
Timer & start()
Zero and start the timer.
Definition Timer.h:95
DefaultTimeUnit markLap()
Get the time elapsed between calls to markLap(). If this is the first markLap() call,...
Definition Timer.h:117
std::chrono::steady_clock Clock
Definition Timer.h:16
NumberType getDeltaUs() const
Definition Timer.h:178
The root for all renderer implementations.
Definition EEngineProject.h:6