Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTimer

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

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

RWTimer uses the system-dpendent function clock() which returns the number of "ticks" since it was first called. As a result, RWTimer will not be able to measure intervals longer than some system-dependent value. (For instance, on several common UNIX systems, this value is just under 36 minutes.)

Persistence

None

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 = RWTime::now())
 {;}

 t.stop();                  // Stop the timer

 cout << t.elapsedTime() << endl;
 return 0;
}
 

Program output (exact value may differ):

5.054945

Public Constructor

RWTimer();

Public Member Functions

double
elapsedTime() const;
void
reset();
void
start();
void
stop();


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.