AuroraRuntime/Include/Aurora/Time/TimerHighRes.hpp

35 lines
747 B
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: TimerHighRes.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Time
{
class TimerHighRes
{
public:
TimerHighRes()
{
Start();
}
void Start()
{
start_ = CurrentInternalClockNS();
}
AuUInt64 End()
{
auto re = std::clamp<AuInt64>(CurrentInternalClockNS() - start_, AuInt64(0), AuNumericLimits<AuInt64>::max());
if (re == AuNumericLimits<AuInt64>::max()) return 0; // ez overflow in subtract. get out of here in 2-3 branches
return re;
}
private:
AuUInt64 start_;
};
}