Libftpp
A modern C++ library
Chronometre Class Reference

Chronometre class for measuring elapsed time between start and end timestamps. It provides methods to retrieve the elapsed time in various units (nanoseconds, microseconds, milliseconds, seconds) and as a formatted string. More...

#include <chronometre.hpp>

Public Member Functions

 Chronometre ()=default
 
 ~Chronometre ()
 
void start ()
 Start the chronometre. More...
 
void end ()
 End the chronometre. More...
 
void popLastChrono ()
 Remove the last recorded time interval (start and end timestamps). More...
 
double getTimeNanoseconds () const
 Get the elapsed time in nanoseconds between the last start and end timestamps. More...
 
double getTimeMicroseconds () const
 Get the elapsed time in microseconds between the last start and end timestamps. More...
 
double getTimeMilliseconds () const
 Get the elapsed time in milliseconds between the last start and end timestamps. More...
 
double getTimeSeconds () const
 Get the elapsed time in seconds between the last start and end timestamps. More...
 
std::string getTimeString () const
 Get the elapsed time as a formatted string with appropriate units. More...
 

Detailed Description

Chronometre class for measuring elapsed time between start and end timestamps. It provides methods to retrieve the elapsed time in various units (nanoseconds, microseconds, milliseconds, seconds) and as a formatted string.

Chronometre chrono;
chrono.start();
chrono.end();
double elapsed = chrono.getTimeMilliseconds();
std::cout << "Elapsed time: " << elapsed << " ms" << std::endl;
chrono.popLastChrono(); // Remove the last recorded time interval
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
double getTimeMilliseconds() const
Get the elapsed time in milliseconds between the last start and end timestamps.
Definition: chronometre.cpp:73
void end()
End the chronometre.
Definition: chronometre.cpp:25
Warning
start() and end() must be called in pairs before retrieving the elapsed time.

Definition at line 26 of file chronometre.hpp.

Constructor & Destructor Documentation

◆ Chronometre()

Chronometre::Chronometre ( )
default

◆ ~Chronometre()

Chronometre::~Chronometre ( )

Definition at line 3 of file chronometre.cpp.

Member Function Documentation

◆ end()

void Chronometre::end ( )

End the chronometre.

Definition at line 25 of file chronometre.cpp.

◆ getTimeMicroseconds()

double Chronometre::getTimeMicroseconds ( ) const

Get the elapsed time in microseconds between the last start and end timestamps.

Returns
Elapsed time in microseconds.

Definition at line 61 of file chronometre.cpp.

◆ getTimeMilliseconds()

double Chronometre::getTimeMilliseconds ( ) const

Get the elapsed time in milliseconds between the last start and end timestamps.

Returns
Elapsed time in milliseconds.

Definition at line 73 of file chronometre.cpp.

◆ getTimeNanoseconds()

double Chronometre::getTimeNanoseconds ( ) const

Get the elapsed time in nanoseconds between the last start and end timestamps.

Returns
Elapsed time in nanoseconds.

Definition at line 49 of file chronometre.cpp.

◆ getTimeSeconds()

double Chronometre::getTimeSeconds ( ) const

Get the elapsed time in seconds between the last start and end timestamps.

Returns
Elapsed time in seconds.

Definition at line 85 of file chronometre.cpp.

◆ getTimeString()

std::string Chronometre::getTimeString ( ) const

Get the elapsed time as a formatted string with appropriate units.

Warning
You cannot choose the unit, it is determined automatically based on the elapsed time.
Returns
Formatted string representing the elapsed time with units (ns, µs, ms, s).

Definition at line 98 of file chronometre.cpp.

◆ popLastChrono()

void Chronometre::popLastChrono ( )

Remove the last recorded time interval (start and end timestamps).

Definition at line 36 of file chronometre.cpp.

◆ start()

void Chronometre::start ( )

Start the chronometre.

Definition at line 17 of file chronometre.cpp.