rpcs3/Utilities/Timer.h

60 lines
1.3 KiB
C
Raw Normal View History

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