light/modules/time/timer.cppm
light7734 63cb6dfe92
Some checks are pending
continuous-integration/drone/push Build is running
wip: convert from include style to module import style :D
2025-11-04 18:50:59 +03:30

43 lines
776 B
C++

export module time;
import std;
namespace lt::time {
/** Simple timer class to keep track of the elapsed time. */
export class Timer
{
public:
using Clock = std::chrono::steady_clock;
using Duration = std::chrono::duration<double>;
using Timepoint = std::chrono::time_point<std::chrono::steady_clock>;
Timer(Timepoint start = Clock::now());
void reset(Timepoint start = Clock::now());
[[nodiscard]] auto elapsed_time() const -> Duration;
private:
Timepoint m_start;
};
} // namespace lt
module :private;
using namespace lt::time;
Timer::Timer(Timepoint start): m_start(start)
{
}
void Timer::reset(Timepoint start)
{
m_start = start;
}
[[nodiscard]] auto Timer::elapsed_time() const -> Duration
{
return { std::chrono::steady_clock::now() - m_start };
}