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