Class timer#

Class Documentation#

class timer#

RAII-style timer for measuring execution time of code blocks.

Automatically measures elapsed time from construction to destruction. Prints start message on creation and elapsed time on destruction. Useful for profiling and logging performance-critical sections.

Public Functions

inline explicit timer(const std::string &name = std::string("main"))#

Constructor - starts timer with optional name.

Note

Prints “Starting <name>” to stdout

Parameters:

name – Descriptive name for this timer instance (default: “main”)

inline ~timer()#

Destructor - prints elapsed time to stdout.

Automatically called when timer goes out of scope. Prints final elapsed time in seconds.

inline void reset()#

Reset the start time to current moment.

Useful for measuring intermediate segments of longer code blocks or repeating measurements without creating new timer objects.

inline double getDuration()#

Get elapsed duration in seconds since construction/last reset().

Note

Does not reset the timer; use reset() to restart

Note

Uses high_resolution_clock for maximum precision

Returns:

Elapsed time in seconds as double (fractional seconds supported)