#pragma once #include "types.h" #include class Timer { private: bool m_stopped; steady_clock::time_point m_start; steady_clock::time_point m_end; public: Timer() : m_stopped(false) { } void Start() { m_stopped = false; m_start = steady_clock::now(); } void Stop() { m_stopped = true; m_end = steady_clock::now(); } double GetElapsedTimeInSec() const { return double(GetElapsedTimeInMicroSec()) / 1000000.0; } double GetElapsedTimeInMilliSec() const { return double(GetElapsedTimeInMicroSec()) / 1000.0; } u64 GetElapsedTimeInMicroSec() const { steady_clock::time_point now = m_stopped ? m_end : steady_clock::now(); return std::chrono::duration_cast(now - m_start).count(); } u64 GetElapsedTimeInNanoSec() const { steady_clock::time_point now = m_stopped ? m_end : steady_clock::now(); return std::chrono::duration_cast(now - m_start).count(); } u64 GetMsSince(steady_clock::time_point timestamp) { steady_clock::time_point now = m_stopped ? m_end : steady_clock::now(); return std::chrono::duration_cast(now - timestamp).count(); } };