Scopira 20080306

scopira::tool::chrono Class Reference

#include <time.h>

List of all members.

Public Member Functions

 chrono (void)
void reset (void)
void start (void)
void stop (void)
double get_total_time (void) const
double get_lap_time (void) const
double get_running_time (void) const

Detailed Description

A handy class that like a stop watch, can be used to measure the passing of time.

The chrono has two states:

  • stopped
  • running

And two counters:

Sample usage:

    scopira::tool::chrono c;

    while (true) {
      // do work
      if (c.get_running_time() > 60) {
        OUTPUT << "Operation taking too long, aborting.\n";
    OUTPUT << "Total elapsed time (in seconds): " << c.get_total_time() << '\n';
Aleksander Demko

Constructor & Destructor Documentation

scopira::tool::chrono::chrono ( void  )

Constructor. The initial state of the chrono is stopped, so you must explicitly start() it.

The chrono has two counters, both of which are zeroed:

  • the total time counter
  • the last lap counter
Aleksander Demko

Member Function Documentation

double scopira::tool::chrono::get_lap_time ( void  ) const

Gets the lap time, in seconds.

This is the time between the last start() and stop().

the lap time, in seconds.
Aleksander Demko
double scopira::tool::chrono::get_running_time ( void  ) const

Gets the current time, in seconds, since the last start().

This is called when the chrono is running, and can be used to poll the chrono.

the running time, in seconds.
Aleksander Demko
double scopira::tool::chrono::get_total_time ( void  ) const

Gets the total time, in seconds.

The total time is the sum of all the start() - stop() segments since the last reset.

the total time, in seconds.
Aleksander Demko
void scopira::tool::chrono::reset ( void  )

Resets the stop watch counters to zero.

Aleksander Demko
void scopira::tool::chrono::start ( void  )

Starts the chrono.

Aleksander Demko
void scopira::tool::chrono::stop ( void  )

Stops the stop watch (you must have start() it) previously.

get_lap_time() may be used to retreave the time since the start(). This time will be added to the total time, which can be retreived with get_total_time()

Aleksander Demko

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