1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-24 11:43:05 +01:00
rpcs3/Utilities/Timer.h

62 lines
1.2 KiB
C
Raw Normal View History

#pragma once
2020-12-12 13:01:29 +01:00
#include "util/types.hpp"
2013-11-19 11:30:58 +01:00
#include <chrono>
class Timer
{
private:
bool m_stopped;
steady_clock::time_point m_start;
steady_clock::time_point m_end;
public:
Timer() : m_stopped(false), m_start(steady_clock::now())
{
}
void Start()
{
m_stopped = false;
m_start = steady_clock::now();
}
void Stop()
{
m_stopped = true;
m_end = steady_clock::now();
}
double GetElapsedTimeInSec() const
{
2021-04-09 21:12:47 +02:00
return static_cast<double>(GetElapsedTimeInMicroSec()) / 1000000.0;
}
double GetElapsedTimeInMilliSec() const
{
2021-04-09 21:12:47 +02:00
return static_cast<double>(GetElapsedTimeInMicroSec()) / 1000.0;
}
2015-02-18 22:23:31 +01:00
u64 GetElapsedTimeInMicroSec() const
{
2021-04-09 21:12:47 +02:00
const steady_clock::time_point now = m_stopped ? m_end : steady_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(now - m_start).count();
}
2015-02-18 22:23:31 +01:00
u64 GetElapsedTimeInNanoSec() const
{
2021-04-09 21:12:47 +02:00
const steady_clock::time_point now = m_stopped ? m_end : steady_clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(now - m_start).count();
}
2021-04-09 21:12:47 +02:00
u64 GetMsSince(steady_clock::time_point timestamp) const
{
2021-04-09 21:12:47 +02:00
const steady_clock::time_point now = m_stopped ? m_end : steady_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(now - timestamp).count();
}
2013-11-19 11:30:58 +01:00
};