Tools.h++ Manual
104011 Tandem Computers Incorporated 21-191
21
RWTimer
Synopsis
#include <rw/timer.h>
RWTimer timer;
Description This class can measure elapsed CPU (user) time. The timer has two states:
running and stopped. The timer measures the total amount of time spent in
the "running" state since it was either constructed or reset.
The timer is put into the "running" state by calling member function
start()
.
It is put into the "stopped" state by calling
stop()
.
Example This example prints out the amount of CPU time used while looping for 5
seconds (as measured using class RWTime).
#include <rw/timer.h>
#include <rw/rwtime.h>
#include <rw/rstream.h>
main()
{
RWTimer t;
t.start(); // Start the timer
RWTime start;
start.now() // Record starting time
// Loop for 5 seconds;
for (RWTime current; current.seconds() - start.seconds() < 5;
current.now())
{;}
t.stop() Stop the timer
cout << t.elapsedTime() << endl;
return 0;
}