Class Stopwatch

Class Documentation

class Stopwatch

A simple utility class for measuring elapsed time across episodes.

The Stopwatch class allows tracking the duration of multiple timed episodes. It provides functionality to start, stop, and retrieve timing information for the last episode as well as the total duration of all episodes.

Public Functions

void start()

Starts the stopwatch for a new timing episode.

Records the start time for the current episode. If the stopwatch is already running, calling start() has no effect.

void stop()

Stops the stopwatch for the current timing episode.

Records the end time for the current episode and updates the total accumulated duration. If the stopwatch is not running, calling stop() has no effect.

inline bool isRunning() const

Checks if the stopwatch is currently running.

Returns:

true if the stopwatch is running, false otherwise.

inline double getLastEpisodeDuration() const

Gets the duration of the last timing episode.

The value represents the time elapsed during the most recently completed pair of start() and stop() calls. If no episode has been completed, this returns 0.

Returns:

The duration of the last episode in seconds as a double.

inline double getTotalDuration() const

Gets the total accumulated duration of all episodes.

The value represents the sum of the durations of all episodes that have been completed since the creation of the stopwatch or since it was last reset.

Returns:

The total duration in seconds as a double.

inline void reset()

Resets the stopwatch to its initial state.

This method resets all member variables by reassigning the object to a default-constructed instance.