![]() |
UtilsLite
Utilities for C++ programming
|
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. | |
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
|
delete |
|
inline |
|
default |
|
inline |
Return elapsed time (between tic-toc) in milliseconds.
|
inline |
Return elapsed time (between tic-toc) in microseconds.
|
inline |
Return elapsed time (between tic-toc) in nanoseconds.
|
inline |
Return elapsed time (between tic-toc) in seconds.
|
inline |
Start timing.
This function captures the current time point, marking the start of the timing.
|
inline |
End timing.
This function captures the current time point, marking the end of the timing and calculates the elapsed time.