ccls/src/timer.cc

42 lines
1023 B
C++
Raw Normal View History

2017-03-25 19:18:25 +00:00
#include "timer.h"
2017-07-30 00:45:00 +00:00
#include <loguru.hpp>
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();
2017-09-22 01:14:57 +00:00
return std::chrono::duration_cast<std::chrono::microseconds>(end - start)
.count();
}
long long Timer::ElapsedMicrosecondsAndReset() {
std::chrono::time_point<Clock> end = Clock::now();
2017-09-22 01:14:57 +00:00
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-09-22 01:14:57 +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;
2017-09-22 01:14:57 +00:00
LOG_S(INFO) << message << " took " << milliseconds << "." << remaining
<< "ms";
Reset();
}