2025-11-04 18:50:59 +03:30
|
|
|
export module time;
|
|
|
|
|
import std;
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-11-04 18:50:59 +03:30
|
|
|
namespace lt::time {
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-15 15:53:30 +03:30
|
|
|
/** Simple timer class to keep track of the elapsed time. */
|
2025-11-04 18:50:59 +03:30
|
|
|
export class Timer
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
|
|
|
|
public:
|
2025-07-15 15:11:03 +03:30
|
|
|
using Clock = std::chrono::steady_clock;
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-15 15:53:30 +03:30
|
|
|
using Duration = std::chrono::duration<double>;
|
|
|
|
|
|
|
|
|
|
using Timepoint = std::chrono::time_point<std::chrono::steady_clock>;
|
|
|
|
|
|
2025-07-15 15:11:03 +03:30
|
|
|
Timer(Timepoint start = Clock::now());
|
2025-07-07 15:13:05 +03:30
|
|
|
|
2025-07-15 15:11:03 +03:30
|
|
|
void reset(Timepoint start = Clock::now());
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-15 15:11:03 +03:30
|
|
|
[[nodiscard]] auto elapsed_time() const -> Duration;
|
2025-07-05 16:07:51 +03:30
|
|
|
|
|
|
|
|
private:
|
2025-07-15 15:11:03 +03:30
|
|
|
Timepoint m_start;
|
2025-07-05 13:28:41 +03:30
|
|
|
};
|
|
|
|
|
|
2025-07-11 00:05:48 +03:30
|
|
|
} // namespace lt
|
2025-11-04 18:50:59 +03:30
|
|
|
|
|
|
|
|
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 };
|
|
|
|
|
}
|