Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Stopwatch.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4
6
7namespace storm {
8namespace utility {
9
13class Stopwatch {
14 public:
15 typedef decltype(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::seconds::zero()).count()) SecondType;
16 typedef decltype(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::milliseconds::zero()).count()) MilisecondType;
17 typedef decltype(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::nanoseconds::zero()).count()) NanosecondType;
18
24 Stopwatch(bool startNow = false);
25
30
35
40
46 void addToTime(std::chrono::nanoseconds timeNanoseconds);
47
51 void add(Stopwatch const& other);
52
56 void stop();
57
61 void start();
62
66 void reset();
67
71 void restart();
72
76 bool stopped() const;
77
78 friend std::ostream& operator<<(std::ostream& out, Stopwatch const& stopwatch);
79
80 private:
81 // The time accumulated so far.
82 std::chrono::nanoseconds accumulatedTime;
83
84 // A flag indicating if the stopwatch is stopped right now.
85 bool isStopped;
86
87 // The timepoint when the stopwatch was started the last time (if it's not stopped).
88 std::chrono::high_resolution_clock::time_point startOfCurrentMeasurement;
89};
90
91std::ostream& operator<<(std::ostream& out, Stopwatch const& stopwatch);
92} // namespace utility
93} // namespace storm
A class that provides convenience operations to display run times.
Definition Stopwatch.h:13
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:16
Stopwatch(bool startNow=false)
Constructor.
Definition Stopwatch.cpp:6
MilisecondType getTimeInMilliseconds() const
Gets the measured time in milliseconds.
Definition Stopwatch.cpp:21
friend std::ostream & operator<<(std::ostream &out, Stopwatch const &stopwatch)
Definition Stopwatch.cpp:68
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:15
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:17
void add(Stopwatch const &other)
Adds the value of the (stopped) watch to the accumulated time of this watch.
Definition Stopwatch.cpp:37
std::ostream & operator<<(std::ostream &os, Engine const &engine)
Writes the string representation of the given engine to the given stream.
Definition Engine.cpp:59