OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
StopWatch.cpp
Go to the documentation of this file.
1#include "StopWatch.h"
2#include <sstream>
3#include <iomanip>
4
5using namespace std::chrono;
6
7namespace Utils
8{
10 : m_stopped(false)
11 {
12 if (start)
13 {
14 this->start();
15 }
16 }
17
19 {
20 m_stopped = false;
21 m_started = system_clock::now();
22 }
23
25 {
26 m_finished = system_clock::now();
27 m_stopped = true;
28 }
29
31 {
32 return duration_cast<milliseconds>(getElapsedDuration()).count();
33 }
34
36 {
38 }
39
40 std::string StopWatch::getElapsedSecondsString(const std::string& suffix /*= ""*/) const
41 {
42 std::stringstream ss;
43 ss << std::fixed << std::setprecision(3) << getElapsedSeconds() << suffix;
44 return ss.str();
45 }
46
47 system_clock::duration StopWatch::getElapsedDuration() const
48 {
49 // if stop() hasn't been called yet, use the current time
50 if (m_stopped) return m_finished - m_started;
51 else return system_clock::now() - m_started;
52 }
53}
std::string getElapsedSecondsString(const std::string &suffix="") const
Definition StopWatch.cpp:40
static constexpr const double MS_PER_SECOND
Definition StopWatch.h:27
long long getElapsedMilliseconds() const
Definition StopWatch.cpp:30
double getElapsedSeconds() const
Definition StopWatch.cpp:35
std::chrono::system_clock::duration getElapsedDuration() const
Definition StopWatch.cpp:47
StopWatch(bool start)
Definition StopWatch.cpp:9