Scopira  20080306
scopira::tool::chrono Class Reference

#include <time.h>

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:

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

Constructor & Destructor Documentation

◆ chrono()

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
Author
Aleksander Demko

Member Function Documentation

◆ get_lap_time()

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().

Returns
the lap time, in seconds.
Author
Aleksander Demko

◆ get_running_time()

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.

Returns
the running time, in seconds.
Author
Aleksander Demko

◆ get_total_time()

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.

Returns
the total time, in seconds.
Author
Aleksander Demko

◆ reset()

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

Resets the stop watch counters to zero.

Author
Aleksander Demko

◆ start()

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

Starts the chrono.

Author
Aleksander Demko

◆ stop()

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()

Author
Aleksander Demko

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