Libftpp
A modern C++ library
chronometre.hpp
Go to the documentation of this file.
1 #ifndef CHRONOMETRE_HPP
2 #define CHRONOMETRE_HPP
3 
4 #include <chrono>
5 #include <stdexcept>
6 #include <string>
7 #include <vector>
8 
27 {
28 private:
29  std::vector<double> _timestamps;
30  std::chrono::_V2::system_clock::time_point _now;
31 
32  void createTimestamp();
33 
34 public:
35  Chronometre() = default;
36  ~Chronometre();
37 
38  void start();
39  void end();
40 
41  void popLastChrono();
42 
43  double getTimeNanoseconds() const;
44  double getTimeMicroseconds() const;
45  double getTimeMilliseconds() const;
46  double getTimeSeconds() const;
47  std::string getTimeString() const;
48 };
49 
50 #endif
Chronometre class for measuring elapsed time between start and end timestamps. It provides methods to...
Definition: chronometre.hpp:27
void start()
Start the chronometre.
Definition: chronometre.cpp:17
void popLastChrono()
Remove the last recorded time interval (start and end timestamps).
Definition: chronometre.cpp:36
std::string getTimeString() const
Get the elapsed time as a formatted string with appropriate units.
Definition: chronometre.cpp:98
double getTimeMicroseconds() const
Get the elapsed time in microseconds between the last start and end timestamps.
Definition: chronometre.cpp:61
Chronometre()=default
double getTimeSeconds() const
Get the elapsed time in seconds between the last start and end timestamps.
Definition: chronometre.cpp:85
double getTimeMilliseconds() const
Get the elapsed time in milliseconds between the last start and end timestamps.
Definition: chronometre.cpp:73
double getTimeNanoseconds() const
Get the elapsed time in nanoseconds between the last start and end timestamps.
Definition: chronometre.cpp:49
void end()
End the chronometre.
Definition: chronometre.cpp:25