AuroraRuntime/Include/Aurora/Time/Stopwatch.hpp

68 lines
1.3 KiB
C++
Raw Normal View History

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Stopwatch.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
#include "StaticClocksDirect.hpp"
#include "StaticClocksClasses.hpp"
namespace Aurora::Time
{
template <typename DefaultClock_t = ClockSteady>
struct Stopwatch
{
inline Stopwatch()
{
Start();
}
inline ~Stopwatch()
{
}
inline void Start()
{
this->qwStart_ = GetTimeInNanosecond();
}
inline void Reset()
{
this->qwStart_ = GetTimeInNanosecond();
this->qwEnd_ = 0;
}
inline AuUInt64 EndNS()
{
if (!this->qwEnd_)
{
this->qwEnd_ = GetTimeInNanosecond();
}
return this->qwEnd_ - this->qwStart_;
}
inline AuUInt64 EndMS()
{
if (!this->qwEnd_)
{
this->qwEnd_ = GetTimeInNanosecond();
}
return AuNSToMS<AuUInt64>(this->qwEnd_ - this->qwStart_);
}
private:
AuUInt64 qwStart_ {};
AuUInt64 qwEnd_ {};
inline AuUInt64 GetTimeInNanosecond()
{
return Clock<DefaultClock_t>::GetCurrentTimeNS();
}
};
}