mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-09 08:21:18 +12:00
Add all the files
This commit is contained in:
parent
e3db07a16a
commit
d60742f52b
1445 changed files with 430238 additions and 0 deletions
75
src/util/highresolutiontimer/HighResolutionTimer.h
Normal file
75
src/util/highresolutiontimer/HighResolutionTimer.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
#pragma once
|
||||
|
||||
using HRTick = uint64;
|
||||
|
||||
class HighResolutionTimer
|
||||
{
|
||||
public:
|
||||
HighResolutionTimer()
|
||||
{
|
||||
m_timePoint = 0;
|
||||
}
|
||||
|
||||
HRTick getTick() const
|
||||
{
|
||||
return m_timePoint;
|
||||
}
|
||||
|
||||
uint64 getTickInSeconds() const
|
||||
{
|
||||
return m_timePoint / m_freq;
|
||||
}
|
||||
|
||||
// return time difference in seconds, this is an utility function mainly intended for debugging/benchmarking purposes. Avoid using doubles for precise timing
|
||||
static double getTimeDiff(HRTick startTime, HRTick endTime)
|
||||
{
|
||||
return (double)(endTime - startTime) / (double)m_freq;
|
||||
}
|
||||
|
||||
// returns tick difference and frequency
|
||||
static uint64 getTimeDiffEx(HRTick startTime, HRTick endTime, uint64& freq)
|
||||
{
|
||||
freq = m_freq;
|
||||
return endTime - startTime;
|
||||
}
|
||||
|
||||
static HighResolutionTimer now();
|
||||
static HRTick getFrequency();
|
||||
|
||||
private:
|
||||
HighResolutionTimer(uint64 timePoint) : m_timePoint(timePoint) {};
|
||||
|
||||
uint64 m_timePoint;
|
||||
static uint64 m_freq;
|
||||
};
|
||||
|
||||
// benchmark helper utility
|
||||
// measures time between Start() and Stop() call
|
||||
class BenchmarkTimer
|
||||
{
|
||||
public:
|
||||
void Start()
|
||||
{
|
||||
m_startTime = HighResolutionTimer::now().getTick();
|
||||
}
|
||||
|
||||
void Stop()
|
||||
{
|
||||
m_stopTime = HighResolutionTimer::now().getTick();
|
||||
}
|
||||
|
||||
double GetElapsedMilliseconds() const
|
||||
{
|
||||
cemu_assert_debug(m_startTime != 0 && m_stopTime != 0);
|
||||
cemu_assert_debug(m_startTime <= m_stopTime);
|
||||
uint64 tickDif = m_stopTime - m_startTime;
|
||||
double freq = (double)HighResolutionTimer::now().getFrequency();
|
||||
double elapsedMS = (double)tickDif * 1000.0 / freq;
|
||||
return elapsedMS;
|
||||
}
|
||||
|
||||
private:
|
||||
HRTick m_startTime{};
|
||||
HRTick m_stopTime{};
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue