AuroraRuntime/Include/Aurora/Time/TimerHighRes.hpp
2021-06-27 22:25:29 +01:00

35 lines
755 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), std::numeric_limits<AuInt64>::max());
if (re == std::numeric_limits<AuInt64>::max()) return 0; // ez overflow in subtract. get out of here in 2-3 branches
return re;
}
private:
AuUInt64 start_;
};
}