NotificationModule/src/gui/Timer.h

19 lines
394 B
C
Raw Permalink Normal View History

2023-01-21 20:37:04 +01:00
#include <ctime>
#include <iostream>
class Timer {
public:
Timer() { clock_gettime(CLOCK_MONOTONIC, &beg_); }
2023-01-21 20:37:04 +01:00
double elapsed() {
clock_gettime(CLOCK_MONOTONIC, &end_);
2023-01-21 20:37:04 +01:00
return end_.tv_sec - beg_.tv_sec +
(end_.tv_nsec - beg_.tv_nsec) / 1000000000.;
}
void reset() { clock_gettime(CLOCK_MONOTONIC, &beg_); }
2023-01-21 20:37:04 +01:00
private:
timespec beg_, end_;
};