2017-03-25 19:18:25 +00:00
|
|
|
#include "timer.h"
|
|
|
|
|
2017-03-31 04:13:58 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-03-25 19:18:25 +00:00
|
|
|
Timer::Timer() {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2017-05-17 07:08:45 +00:00
|
|
|
long long Timer::ElapsedMicroseconds() const {
|
|
|
|
std::chrono::time_point<Clock> end = Clock::now();
|
|
|
|
return std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
|
|
|
}
|
|
|
|
|
|
|
|
long long Timer::ElapsedMicrosecondsAndReset() {
|
|
|
|
std::chrono::time_point<Clock> end = Clock::now();
|
|
|
|
long long microseconds = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
|
|
|
Reset();
|
|
|
|
return microseconds;
|
|
|
|
}
|
|
|
|
|
2017-03-25 19:18:25 +00:00
|
|
|
void Timer::Reset() {
|
|
|
|
start = Clock::now();
|
|
|
|
}
|
|
|
|
|
2017-03-31 04:13:58 +00:00
|
|
|
void Timer::ResetAndPrint(const std::string& message) {
|
2017-03-25 19:18:25 +00:00
|
|
|
std::chrono::time_point<Clock> end = Clock::now();
|
2017-04-24 01:24:09 +00:00
|
|
|
long long elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
|
|
|
|
|
|
|
long long milliseconds = elapsed / 1000;
|
|
|
|
long long remaining = elapsed - milliseconds;
|
|
|
|
|
|
|
|
std::cerr << message << " took " << milliseconds << "." << remaining << "ms" << std::endl;
|
|
|
|
Reset();
|
|
|
|
}
|