You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
620 B
33 lines
620 B
1 year ago
|
|
||
|
#ifndef CPP_START_STOP_WATCH_H
|
||
|
#define CPP_START_STOP_WATCH_H
|
||
|
|
||
|
#include <chrono>
|
||
|
|
||
|
|
||
|
class StopWatch {
|
||
|
|
||
|
private:
|
||
|
|
||
|
std::chrono::time_point<std::chrono::high_resolution_clock> mBegin;
|
||
|
|
||
|
public:
|
||
|
StopWatch() : mBegin(std::chrono::high_resolution_clock::now()) {
|
||
|
|
||
|
}
|
||
|
|
||
|
void reset() {
|
||
|
mBegin = std::chrono::high_resolution_clock::now();
|
||
|
}
|
||
|
|
||
|
template<typename Duration=std::chrono::milliseconds>
|
||
|
int64_t elapsed() const {
|
||
|
return std::chrono::duration_cast<Duration>(std::chrono::high_resolution_clock::now() - mBegin)
|
||
|
.count();
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
|
||
|
#endif //CPP_START_STOP_WATCH_H
|