2020-04-08 18:08:14 +02:00
|
|
|
/**
|
|
|
|
* @file Stopwatch.h
|
|
|
|
*
|
|
|
|
* @date 08.04.2020
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
|
|
|
|
#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
|
|
|
|
#include <framework/timemanager/Clock.h>
|
|
|
|
|
2020-04-08 18:27:18 +02:00
|
|
|
/**
|
|
|
|
* @brief Simple Stopwatch implementation to measure elapsed time
|
|
|
|
* @details
|
|
|
|
* This class can be used to measure elapsed times. It also displays elapsed
|
|
|
|
* times automatically on destruction if not explicitely deactivated in the
|
|
|
|
* constructor. The default time format is the elapsed time in miliseconds
|
|
|
|
* as a float.
|
|
|
|
* This class caches the value
|
|
|
|
*/
|
2020-04-08 18:08:14 +02:00
|
|
|
class Stopwatch {
|
|
|
|
enum class DisplayMode {
|
2020-04-08 18:27:18 +02:00
|
|
|
MS_DOUBLE,
|
2020-04-08 18:08:14 +02:00
|
|
|
MS
|
|
|
|
};
|
|
|
|
|
|
|
|
Stopwatch(bool displayOnDestruction = true, DisplayMode displayMode =
|
2020-04-08 18:27:18 +02:00
|
|
|
DisplayMode::MS_DOUBLE);
|
2020-04-08 18:08:14 +02:00
|
|
|
virtual~ Stopwatch();
|
|
|
|
|
|
|
|
void start();
|
|
|
|
|
|
|
|
ms_normal_t stop();
|
|
|
|
ms_double_t stopPrecise();
|
|
|
|
|
|
|
|
void display();
|
|
|
|
private:
|
|
|
|
|
|
|
|
timeval startTime {0, 0};
|
|
|
|
timeval elapsedTime {0, 0};
|
2020-04-08 18:27:18 +02:00
|
|
|
double elapsedTimeMsDouble = 0;
|
2020-04-08 18:08:14 +02:00
|
|
|
|
|
|
|
bool displayOnDestruction = true;
|
2020-04-08 18:27:18 +02:00
|
|
|
DisplayMode displayMode = DisplayMode::MS_DOUBLE;
|
2020-04-08 18:08:14 +02:00
|
|
|
|
|
|
|
void stopInternal();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ */
|