UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
Utils::TicToc Class Reference

A class for timing code execution. More...

#include <TicToc.hxx>

Public Member Functions

 TicToc (TicToc const &)=delete
 
TicToc const & operator= (TicToc const &) const =delete
 
 TicToc ()
 Constructs a TicToc object and starts the timer.
 
 ~TicToc ()=default
 
void tic ()
 Start timing.
 
void toc ()
 End timing.
 
real_type elapsed_s () const
 Return elapsed time (between tic-toc) in seconds.
 
real_type elapsed_ms () const
 Return elapsed time (between tic-toc) in milliseconds.
 
real_type elapsed_mus () const
 Return elapsed time (between tic-toc) in microseconds.
 
real_type elapsed_ns () const
 Return elapsed time (between tic-toc) in nanoseconds.
 

Detailed Description

A class for timing code execution.

The TicToc class provides a simple and efficient way to measure the execution time of code segments. It uses high-resolution clocks for precise timing, allowing users to track performance and optimize code execution times.

Usage

To measure execution time, instantiate a TicToc object, call tic() to start timing, and toc() to stop timing. You can then retrieve the elapsed time in various units such as seconds, milliseconds, microseconds, or nanoseconds.

Example

TicToc timer;
timer.tic();
// ... code to be timed ...
timer.toc();
std::cout << "Elapsed time: " << timer.elapsed_ms() << " ms" << std::endl;
void tic()
Start timing.
Definition TicToc.hxx:202
void toc()
End timing.
Definition TicToc.hxx:212
real_type elapsed_ms() const
Return elapsed time (between tic-toc) in milliseconds.
Definition TicToc.hxx:229
TicToc(TicToc const &)=delete

Constructor & Destructor Documentation

◆ TicToc() [1/2]

Utils::TicToc::TicToc ( TicToc const & )
delete

◆ TicToc() [2/2]

Utils::TicToc::TicToc ( )
inline

Constructs a TicToc object and starts the timer.

The constructor initializes the elapsed time to zero and calls the tic() function to start the timing.

◆ ~TicToc()

Utils::TicToc::~TicToc ( )
default

Member Function Documentation

◆ elapsed_ms()

real_type Utils::TicToc::elapsed_ms ( ) const
inline

Return elapsed time (between tic-toc) in milliseconds.

Returns
The elapsed time in milliseconds as a double.

◆ elapsed_mus()

real_type Utils::TicToc::elapsed_mus ( ) const
inline

Return elapsed time (between tic-toc) in microseconds.

Returns
The elapsed time in microseconds as a double.

◆ elapsed_ns()

real_type Utils::TicToc::elapsed_ns ( ) const
inline

Return elapsed time (between tic-toc) in nanoseconds.

Returns
The elapsed time in nanoseconds as a double.

◆ elapsed_s()

real_type Utils::TicToc::elapsed_s ( ) const
inline

Return elapsed time (between tic-toc) in seconds.

Returns
The elapsed time in seconds as a double.

◆ operator=()

TicToc const & Utils::TicToc::operator= ( TicToc const & ) const
delete

◆ tic()

void Utils::TicToc::tic ( )
inline

Start timing.

This function captures the current time point, marking the start of the timing.

◆ toc()

void Utils::TicToc::toc ( )
inline

End timing.

This function captures the current time point, marking the end of the timing and calculates the elapsed time.


The documentation for this class was generated from the following file: