ccls/src/timer.cc

34 lines
956 B
C++
Raw Normal View History

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();
}
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();
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();
}