class Chronograph

Simple timer class that allows to measure elapsed times in real seconds as well as CPU used sec

Public Methods

Chronograph()
creator - no arguments - starts also the Chronograph
~Chronograph()
destructor - does nothing

Public

getting the time information of the chronograph
double lap()
returns the number of CPU seconds since the last time lap was called
double elapsed()
returns the number of CPU seconds
double time_interval()
returns the total time interval (i.e. not the CPU seconds)
double elapsedHMS(double &Hours, double &Mins, double &Secs)
returns the elapsed time in seconds as well as Hours, Mins and Secs
starting and stopping the chronograph
double start()
reset and start the chronograph
double stop()
stop it and return the time since start
int isstopped()
returns non-zero if stopped (i.e. the value of the private member)
double reset()
stops the chronograph and initializes all the time to the current time

Private Fields

double _elapsed
the last elapsed time taken
clock_t _lastlap
when the last lap was read
clock_t _start
when the Chronograph was started
struct timespec _start_time
in keep track how many (real time) sec have passed
clock_t _stopped
when the Chronograph was stopped, if _stopped != 0 it is stopped

Private Methods

double diff(clock_t start, clock_t end)
diff() calculates the difference IN SECONDS between two clock_t values.

Documentation

Simple timer class that allows to measure elapsed times in real seconds as well as CPU used sec. (pirated from CUJ)

Note that the Chronograph keeps track of the CPU seconds as well as the real seconds passed. Thus one can use it for measureing the actual time a piece of code takes as well as the number of seconds that it takes in total.

USAGE:

     Chronograph *my_chrono = new Chronograph();
     // do something
     my_chrono->stop();
     double nSecCpu = my_chrono->elapsed();
     double nSecTotal = my_chrono->time_interval();

     my_chrono->start(); // note start also resets the Chronograph
     
     // etc etc

MODIFICATIONS :

Chronograph()
creator - no arguments - starts also the Chronograph

~Chronograph()
destructor - does nothing

starting and stopping the chronograph

double start()
reset and start the chronograph

double stop()
stop it and return the time since start

int isstopped()
returns non-zero if stopped (i.e. the value of the private member)

double reset()
stops the chronograph and initializes all the time to the current time

getting the time information of the chronograph

double lap()
returns the number of CPU seconds since the last time lap was called

double elapsed()
returns the number of CPU seconds

double time_interval()
returns the total time interval (i.e. not the CPU seconds)

double elapsedHMS(double &Hours, double &Mins, double &Secs)
returns the elapsed time in seconds as well as Hours, Mins and Secs

clock_t _start
when the Chronograph was started

clock_t _stopped
when the Chronograph was stopped, if _stopped != 0 it is stopped

clock_t _lastlap
when the last lap was read

double _elapsed
the last elapsed time taken

struct timespec _start_time
in keep track how many (real time) sec have passed

double diff(clock_t start, clock_t end)
diff() calculates the difference IN SECONDS between two clock_t values.


This class has no child classes.
Author:
C.Witzig
Date: Feb 2, 98
Version:
Last update Mar 21, 98

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de