1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#pragma once
#include <cstdint>
namespace nCine
{
/// Accumulates the time between starting and stopping the time measurement
class Timer
{
public:
Timer();
/// Starts the timer
void start();
/// Stops the timer
void stop();
/// Resets the accumulated time
inline void reset() {
_accumulatedTime = 0ULL;
}
/// Returns `true` if the timer is running
inline bool isRunning() const {
return _isRunning;
}
/// Returns elapsed time in seconds since last starting the timer
float interval() const;
/// Returns total accumulated time in seconds
float total() const;
private:
bool _isRunning;
/// Start time mark
std::uint64_t _startTime;
/// Accumulated time ticks over multiple start and stop
std::uint64_t _accumulatedTime;
};
}
|