2021-11-03 11:19:01 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 03.11.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Timer.h"
|
|
|
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
|
|
|
void Timer::start() {
|
|
|
|
_startTime = high_resolution_clock::now();
|
|
|
|
_isRunning = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::stop() {
|
|
|
|
_endTime = high_resolution_clock::now();
|
|
|
|
_isRunning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Timer::elapsedMilliseconds() const {
|
2021-11-05 21:55:34 +03:00
|
|
|
return elapsedSeconds()*1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Timer::elapsedSeconds() const {
|
2021-11-03 11:19:01 +03:00
|
|
|
high_resolution_clock::time_point endTime;
|
|
|
|
|
|
|
|
if(_isRunning) {
|
|
|
|
endTime = high_resolution_clock::now();
|
|
|
|
} else {
|
|
|
|
endTime = _endTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
return duration<double>(endTime - _startTime).count();
|
|
|
|
}
|