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
5
using namespace
std::chrono;
6
7
namespace
Utils
8
{
9
StopWatch::StopWatch
(
bool
start)
10
: m_stopped(false)
11
{
12
if
(
start
)
13
{
14
this->
start
();
15
}
16
}
17
18
void
StopWatch::start
()
19
{
20
m_stopped =
false
;
21
m_started = system_clock::now();
22
}
23
24
void
StopWatch::stop
()
25
{
26
m_finished = system_clock::now();
27
m_stopped =
true
;
28
}
29
30
long
long
StopWatch::getElapsedMilliseconds
()
const
31
{
32
return
duration_cast<milliseconds>(
getElapsedDuration
()).count();
33
}
34
35
double
StopWatch::getElapsedSeconds
()
const
36
{
37
return
getElapsedMilliseconds
() /
MS_PER_SECOND
;
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
}
StopWatch.h
Utils::StopWatch::getElapsedSecondsString
std::string getElapsedSecondsString(const std::string &suffix="") const
Definition
StopWatch.cpp:40
Utils::StopWatch::MS_PER_SECOND
static constexpr const double MS_PER_SECOND
Definition
StopWatch.h:27
Utils::StopWatch::start
void start()
Definition
StopWatch.cpp:18
Utils::StopWatch::getElapsedMilliseconds
long long getElapsedMilliseconds() const
Definition
StopWatch.cpp:30
Utils::StopWatch::getElapsedSeconds
double getElapsedSeconds() const
Definition
StopWatch.cpp:35
Utils::StopWatch::getElapsedDuration
std::chrono::system_clock::duration getElapsedDuration() const
Definition
StopWatch.cpp:47
Utils::StopWatch::StopWatch
StopWatch(bool start)
Definition
StopWatch.cpp:9
Utils::StopWatch::stop
void stop()
Definition
StopWatch.cpp:24
Utils
Definition
ArchiveExtractor.cpp:15
Utils
StopWatch.cpp
Generated by
1.9.8