Helios++
Helios software for LiDAR simulations
TimeWatcher.h
1 #pragma once
2 
3 #include <chrono>
4 #include <iostream>
5 #include <string>
6 #include <memory>
7 
14 public:
15  // *** CONSTRUCTOR *** //
16  // ******************* //
20  TimeWatcher();
21 
22  // *** PUBLIC METHODS *** //
23  // ********************** //
28  void start();
33  void stop();
41  std::shared_ptr<std::chrono::high_resolution_clock::duration>
47  double getElapsedDecimalSeconds();
52  long getElapsedSeconds();
57  long getElapsedMillis();
62  long getElapsedNanos();
67  std::string getElapsedFormat();
73  void reportSeconds(
74  std::string msg = "Total elapsed seconds: "
75  );
76 
82  void reportMillis(
83  std::string msg = "Total elapsed milliseconds: "
84  );
85 
92  void reportFormat(
93  std::string msg = "Total elapsed time: "
94  );
95 private:
96  // *** ATTRIBUTES *** //
97  // ******************** //
103  std::unique_ptr<std::chrono::high_resolution_clock::time_point> tStart;
109  std::unique_ptr<std::chrono::high_resolution_clock::time_point> tEnd;
110 
111  // *** PRIVATE METHODS *** //
112  // *********************** //
119  bool hasNulls();
120 };
bool hasNulls()
Check if the time watcher has null start or end time points.
Definition: TimeWatcher.cpp:92
A time watcher can be used to perform and report time measures.
Definition: TimeWatcher.h:13
long getElapsedMillis()
Obtain the elapsed time as the integer number of milliseconds.
Definition: TimeWatcher.cpp:46
double getElapsedDecimalSeconds()
Obtain the elapsed time as the real number of seconds.
Definition: TimeWatcher.cpp:37
std::unique_ptr< std::chrono::high_resolution_clock::time_point > tEnd
End time point.
Definition: TimeWatcher.h:109
std::string getElapsedFormat()
Obtain the elapsed time as a string with format "HH:MM:SS".
Definition: TimeWatcher.cpp:59
long getElapsedNanos()
Obtain the elapsed time as the integer number of nanoseconds.
Definition: TimeWatcher.cpp:52
void stop()
Stop the time watcher, which sets the ending point for a time measure.
Definition: TimeWatcher.cpp:22
std::shared_ptr< std::chrono::high_resolution_clock::duration > getElapsedTime()
Obtain the elapsed time as the difference between the last start() and the last stop() invocations...
Definition: TimeWatcher.cpp:31
void reportMillis(std::string msg="Total elapsed milliseconds: ")
Report elapsed seconds through specified output stream.
Definition: TimeWatcher.cpp:78
TimeWatcher()
Instantiate a time watcher.
Definition: TimeWatcher.cpp:8
void start()
Start the time watcher, which sets the starting point for a time measure.
Definition: TimeWatcher.cpp:15
long getElapsedSeconds()
Obtain the elapsed time as the integer number of seconds.
Definition: TimeWatcher.cpp:40
void reportFormat(std::string msg="Total elapsed time: ")
Report elapsed time through specified output stream using "HH:MM:SS" format.
Definition: TimeWatcher.cpp:84
void reportSeconds(std::string msg="Total elapsed seconds: ")
Report elapsed seconds through specified output stream.
Definition: TimeWatcher.cpp:72
std::unique_ptr< std::chrono::high_resolution_clock::time_point > tStart
Start time point.
Definition: TimeWatcher.h:103