ccls/src/timer.cc

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