|
Compaq C++
Compaq C++ Class Library Reference Manual
Chapter 8 Stopwatch Package
The Stopwatch package provides ways to measure intervals of program
execution time. The package consists of a single class,
Stopwatch
. Typically, you use this class during the performance-tuning phase of
program development.
Stopwatch class
Provides the means to measure intervals of time between specified
program events.
Header
#include <stopwatch.hxx>
Alternative Header
#include <Stopwatch.h>
Declaration
class Stopwatch
{
public:
Stopwatch();
void start();
void stop();
void reset();
int status() const;
double system() const;
double user() const;
double real() const;
static double resolution();
};
|
Description
Objects of this class measure program execution time and return the
result in floating-point seconds. The class includes the
start
,
stop
, and
reset
functions familiar to users of a mechanical stopwatch.
You can time the entire program or select certain portions of the
program to time; for example, a specified loop or program module. You
can create a different
Stopwatch
object for each independent program activity, and name each according
to the activity you intend to measure.
Constructor
Stopwatch()
Constructs a
Stopwatch
object with both time and running status initialized to 0.
Member Functions
double real() const
Returns real time (clock time) in double-precision, floating-point
seconds. You can call this function while the stopwatch is running.
void reset()
Resets the current time measurement to 0 without affecting the value of
status()
. If
status()
is initially nonzero, time measurement continues uninterrupted after
resetting.
double resolution()
Returns the (system dependent) resolution of measured time in
double-precision, floating-point seconds.
void start()
Begins measuring program execution time when
status()
is initially 0 (
status()
becomes nonzero as a consequence of the call). If
status()
is initially nonzero, the call has no effect.
int status() const
Indicates whether the stopwatch is running (returns a value of 1) or
not running (returns a value of 0).
void stop()
Halts measurement of program execution time when
status()
is initially nonzero (
status()
becomes 0 as a consequence of the call). If
status()
is initially 0, the call has no effect.
double system() const
Returns the system CPU time in double-precision, floating-point
seconds. You can call this function while the stopwatch is running.
double user() const
Returns the user CPU time in double-precision, floating-point seconds.
You can call this function while the stopwatch is running.
System Environment
On OpenVMS systems, user time returns the total accumulated
CPU time, and system time returns 0. Resolution is 1/100
second.
Example
|
Stopwatch w ;
w.start() ;
//...
// some computation you want to time goes here
//...
w.stop() ;
cout << "elapsed time was " << w.user() << "\n";
|
Displays the number of seconds the computation takes to run. The result
is a double-precision value.
|
|
|