2017-03-25 19:18:25 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <chrono>
|
2017-03-31 04:13:58 +00:00
|
|
|
#include <string>
|
2017-03-25 19:18:25 +00:00
|
|
|
|
|
|
|
struct Timer {
|
|
|
|
using Clock = std::chrono::high_resolution_clock;
|
|
|
|
|
|
|
|
// Creates a new timer. A timer is always running.
|
|
|
|
Timer();
|
|
|
|
|
2017-05-17 07:08:45 +00:00
|
|
|
// Returns elapsed microseconds.
|
|
|
|
long long ElapsedMicroseconds() const;
|
|
|
|
// Returns elapsed microseconds and restarts/resets the timer.
|
|
|
|
long long ElapsedMicrosecondsAndReset();
|
2017-03-25 19:18:25 +00:00
|
|
|
// Restart/reset the timer.
|
|
|
|
void Reset();
|
2017-03-31 04:13:58 +00:00
|
|
|
// Resets timer and prints a message like "<foo> took 5ms"
|
|
|
|
void ResetAndPrint(const std::string& message);
|
2017-03-25 19:18:25 +00:00
|
|
|
|
|
|
|
// Raw start time.
|
|
|
|
std::chrono::time_point<Clock> start;
|
|
|
|
};
|