mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 20:12:33 +00:00
37 lines
827 B
C++
37 lines
827 B
C++
#pragma once
|
|
|
|
#include <chrono>
|
|
#include <string>
|
|
|
|
struct Timer {
|
|
using Clock = std::chrono::high_resolution_clock;
|
|
|
|
// Creates a new timer. A timer is always running.
|
|
Timer();
|
|
|
|
// Returns elapsed microseconds.
|
|
long long ElapsedMicroseconds() const;
|
|
// Returns elapsed microseconds and restarts/resets the timer.
|
|
long long ElapsedMicrosecondsAndReset();
|
|
// Restart/reset the timer.
|
|
void Reset();
|
|
// Resets timer and prints a message like "<foo> took 5ms"
|
|
void ResetAndPrint(const std::string& message);
|
|
// Pause the timer.
|
|
void Pause();
|
|
// Resume the timer after it has been paused.
|
|
void Resume();
|
|
|
|
// Raw start time.
|
|
std::chrono::time_point<Clock> start_;
|
|
// Elapsed time.
|
|
long long elapsed_;
|
|
};
|
|
|
|
struct ScopedPerfTimer {
|
|
~ScopedPerfTimer();
|
|
|
|
std::string message_;
|
|
Timer timer_;
|
|
};
|