Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Stopwatch.cpp
Go to the documentation of this file.
2
3namespace storm {
4namespace utility {
5
6Stopwatch::Stopwatch(bool startNow)
7 : accumulatedTime(std::chrono::nanoseconds::zero()), isStopped(true), startOfCurrentMeasurement(std::chrono::nanoseconds::zero()) {
8 if (startNow) {
9 start();
10 }
11}
12
14 auto time = accumulatedTime;
15 if (!this->stopped()) {
16 time += std::chrono::high_resolution_clock::now() - startOfCurrentMeasurement;
17 }
18 return std::chrono::duration_cast<std::chrono::seconds>(time).count();
19}
20
22 auto time = accumulatedTime;
23 if (!this->stopped()) {
24 time += std::chrono::high_resolution_clock::now() - startOfCurrentMeasurement;
25 }
26 return std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
27}
28
30 return accumulatedTime.count();
31}
32
33void Stopwatch::addToTime(std::chrono::nanoseconds timeNanoseconds) {
34 accumulatedTime += timeNanoseconds;
35}
36
37void Stopwatch::add(Stopwatch const& other) {
38 STORM_LOG_WARN_COND(other.stopped(), "Expected stopped watch.");
39 accumulatedTime += other.accumulatedTime;
40}
41
43 STORM_LOG_WARN_COND(!isStopped, "Stopwatch is already paused.");
44 isStopped = true;
45 accumulatedTime += std::chrono::high_resolution_clock::now() - startOfCurrentMeasurement;
46}
47
49 STORM_LOG_WARN_COND(isStopped, "Stopwatch is already running.");
50 isStopped = false;
51 startOfCurrentMeasurement = std::chrono::high_resolution_clock::now();
52}
53
55 accumulatedTime = std::chrono::nanoseconds::zero();
56 isStopped = true;
57}
58
60 reset();
61 start();
62}
63
64bool Stopwatch::stopped() const {
65 return isStopped;
66}
67
68std::ostream& operator<<(std::ostream& out, Stopwatch const& stopwatch) {
69 char oldFillChar = out.fill('0');
70 out << stopwatch.getTimeInSeconds() << "." << std::setw(3) << (stopwatch.getTimeInMilliseconds() % 1000) << "s";
71 out.fill(oldFillChar);
72 return out;
73}
74
75} // namespace utility
76} // namespace storm
A class that provides convenience operations to display run times.
Definition Stopwatch.h:14
bool stopped() const
Retrieves whether the watch is stopped.
Definition Stopwatch.cpp:64
void addToTime(std::chrono::nanoseconds timeNanoseconds)
Add given time to measured time.
Definition Stopwatch.cpp:33
decltype(std::chrono::duration_cast< std::chrono::milliseconds >(std::chrono::milliseconds::zero()).count()) MilisecondType
Definition Stopwatch.h:17
Stopwatch(bool startNow=false)
Constructor.
Definition Stopwatch.cpp:6
MilisecondType getTimeInMilliseconds() const
Gets the measured time in milliseconds.
Definition Stopwatch.cpp:21
void start()
Start stopwatch (again) and start measuring time.
Definition Stopwatch.cpp:48
NanosecondType getTimeInNanoseconds() const
Gets the measured time in nanoseconds.
Definition Stopwatch.cpp:29
decltype(std::chrono::duration_cast< std::chrono::seconds >(std::chrono::seconds::zero()).count()) SecondType
Definition Stopwatch.h:16
void restart()
Reset the stopwatch and immediately start it.
Definition Stopwatch.cpp:59
SecondType getTimeInSeconds() const
Gets the measured time in seconds.
Definition Stopwatch.cpp:13
void reset()
Reset the stopwatch.
Definition Stopwatch.cpp:54
void stop()
Stop stopwatch and add measured time to total time.
Definition Stopwatch.cpp:42
decltype(std::chrono::duration_cast< std::chrono::nanoseconds >(std::chrono::nanoseconds::zero()).count()) NanosecondType
Definition Stopwatch.h:18
void add(Stopwatch const &other)
Adds the value of the (stopped) watch to the accumulated time of this watch.
Definition Stopwatch.cpp:37
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:38
ValueType zero()
Definition constants.cpp:26
std::ostream & operator<<(std::ostream &os, Engine const &engine)
Writes the string representation of the given engine to the given stream.
Definition Engine.cpp:65
LabParser.cpp.
Definition cli.cpp:18