OWLTimer
Synopsis
#include <owl/timer.h>
OWLTimer timer;
Description
This class can measure elapsed CPU user and system times. The timer has two
states: running and stopped. The timer is put into the "running" state by
calling member function start(). It is put into the "stopped" state
by calling stop(). In addition the timer measures the total amount
of time spent in the "running" state.
Example
This example prints out the amount of CPU time used while sleeping for 5
seconds.
#include <unistd.h>
#include <owl/timer.h>
main()
{
OWLTimer t;
t.start();
// Start the timer
OWLTime start( 0 );
// Record starting time
// Sleep for 5 seconds:
sleep( 5 );
t.stop();
// Stop the timer
cout << t.userTime() << endl;
cout << t.systemTime() << endl;
cout << t.totalTime() << endl;
return 0;
}
Program output (exact value may differ):
0
0
4.994945
Public Constructor
OWLTimer();
Constructs a new timer. The timer will not start running until start()
is called.
Public Member Functions void
reset();
Resets (and stops) the timer.
void
start();
Puts the timer in the "running" state. Time accumulates while in this state.
void
stop();
Puts the timer in the "stopped" state. Time will not accumulate while in
this state.
double
systemTime() const;
Returns the total amount of (CPU) time spent executing in system
mode. Time is given in seconds.
double
totalTime() const;
Returns the total amount of time spent in the "running" state. Time
is given in seconds.
double
userTime() const;
Returns the total amount of (CPU) time spent executing in user
mode. Time is given in seconds.