light/modules/time/timer.cppm
light7734 19187aa1d6
Some checks reported errors
continuous-integration/drone/push Build was killed
wip: feat: lsd
2025-11-18 19:06:44 +03:30

45 lines
799 B
C++

export module time;
import lsd;
namespace lt::time {
/** Simple timer class to keep track of the elapsed time. */
export class Timer
{
public:
using Clock = lsd::chrono::steady_clock;
using Duration = lsd::chrono::duration<f64>;
using Timepoint = lsd::chrono::time_point<lsd::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::time
module :private;
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 { lsd::chrono::steady_clock::now() - m_start };
}
} // namespace lt::time