2012-11-14 23:39:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
2013-11-19 10:30:58 +00:00
|
|
|
#include <chrono>
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
2012-11-14 23:39:56 +00:00
|
|
|
class Timer
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
bool stopped;
|
2013-11-19 10:30:58 +00:00
|
|
|
high_resolution_clock::time_point start;
|
|
|
|
high_resolution_clock::time_point end;
|
2012-11-14 23:39:56 +00:00
|
|
|
|
|
|
|
public:
|
2013-11-19 10:30:58 +00:00
|
|
|
Timer() : stopped(false)
|
2012-11-14 23:39:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
stopped = false;
|
2013-11-19 10:30:58 +00:00
|
|
|
start = high_resolution_clock::now();
|
2012-11-14 23:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Stop()
|
|
|
|
{
|
|
|
|
stopped = true;
|
2013-11-19 10:30:58 +00:00
|
|
|
end = high_resolution_clock::now();
|
2012-11-14 23:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double GetElapsedTimeInSec(){return GetElapsedTimeInMicroSec() / 1000000.0;}
|
|
|
|
double GetElapsedTimeInMilliSec(){return GetElapsedTimeInMicroSec() / 1000.0;}
|
|
|
|
double GetElapsedTimeInMicroSec()
|
|
|
|
{
|
2013-11-19 10:30:58 +00:00
|
|
|
if (!stopped)
|
|
|
|
end = high_resolution_clock::now();
|
|
|
|
return duration_cast<microseconds>(end - start).count();
|
2012-11-14 23:39:56 +00:00
|
|
|
}
|
2013-11-19 10:30:58 +00:00
|
|
|
};
|