/usr/include/leatherman/util/timer.hpp is in libleatherman-dev 1.4.0+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | /**
* @file
* Declares a simple timer class.
*/
#pragma once
#include <chrono>
namespace leatherman { namespace util {
/**
* A simple stopwatch/timer we can use for user feedback. We use the
* std::chrono::steady_clock as we don't want to be affected if the system
* clock changed around us (think ntp skew/leapseconds).
*/
class Timer {
public:
Timer() {
reset();
}
/** @return Returns the time that has passed since last reset in seconds. */
double elapsed_seconds() {
auto now = std::chrono::steady_clock::now();
return std::chrono::duration<double>(now - start_).count();
}
/** @return Returns the time that has passed since last reset in milliseconds. */
int elapsed_milliseconds() {
auto now = std::chrono::steady_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(now - start_).count();
}
/** Resets the clock. */
void reset() {
start_ = std::chrono::steady_clock::now();
}
private:
std::chrono::time_point<std::chrono::steady_clock> start_;
};
}} // namespace leatherman::util
|