cpp-mps/src/stopwatch.hpp

37 lines
969 B
C++

#pragma once
#include <chrono>
/**
* @brief Stopwatches measure the time between two points
* @details
* The stopwatch makes use of std::chronos::steady_clock to measure the time between
* when it was startet and when it was stoped. It returnes the time in seconds.
*/
class Stopwatch {
public:
/**
* @brief Creates a new Stopwatch instance
*/
Stopwatch();
/**
* @brief Start the stopwatch
* @details
* If the watch is started while already running, it restarts
*/
void start();
/**
* @brief Stop the stopwatch
* @returns The elapsed time in seconds as double. If the watch was not started, it returns 0
*/
double stop();
///@returns true if stopwatch is running, false if not
bool isRunning() { return running; }
private:
std::chrono::steady_clock::time_point t_start;
bool running;
};