Jive reference manual
List of all members | Public Member Functions | Static Public Member Functions | Related Functions
jem::util::CPUTimer Class Reference

Measures the elapsed CPU time. More...

#include <jem/util/CPUTimer.h>

Public Member Functions

 CPUTimer ()
 Creates a new CPU timer. More...
 
void swap (CPUTimer &rhs)
 Interchanges the internal state of two timer instances. More...
 
Time time () const
 Returns the elapsed CPU time. More...
 
double toDouble () const
 Returns the elapsed CPU time in seconds as a double. More...
 
void start ()
 Starts this timer. More...
 
void stop ()
 Stops this timer. More...
 
void reset ()
 Sets the elapsed CPU time to zero. More...
 
bool isRunning () const
 Tests whether this timer is in the running state. More...
 

Static Public Member Functions

static Time resolution ()
 Returns the resolution of a CPU timer. More...
 

Related Functions

(Note that these are not member functions.)

io::DataInputoperator> > (io::DataInput &in, CPUTimer &t)
 De-serialization operator. More...
 
io::DataOutputoperator<< (io::DataOutput &out, const CPUTimer &t)
 Serialization operator. More...
 
io::TextOutputoperator<< (io::TextOutput &out, const CPUTimer &t)
 Print operator. More...
 
void swap (CPUTimer &lhs, CPUTimer &rhs)
 Interchanges two CPU timers. More...
 

Detailed Description

The class CPUTimer can be used to measure the duration of an event in terms of the elapsed CPU time. That is, the time that the CPU has executed on behalf of this process or thread. Since the CPU may be executing multiple processes or threads concurrently, the elapsed CPU time may be less than the elapsed wall-clock time.

Like the Timer class, a CPUTimer has two states: a running state, during which its internal clock is ticking, and a stopped state, during which its internal clock is stopped.

See also
Time, Timer.

Constructor & Destructor Documentation

jem::util::CPUTimer::CPUTimer ( )

Creates a CPUTimer in the stopped state with the elapsed time initialized to zero.

Postcondition
thic->isRunning() == false

Member Function Documentation

void jem::util::CPUTimer::swap ( CPUTimer rhs)

Interchanges the internal state of this timer with that of the rhs timer.

Parameters
rhs- a CPUTimer instance.
Time jem::util::CPUTimer::time ( ) const

Returns a Time object representing the CPU time that has elapsed while this timer has been in the running state. The current state of this timer is not affected by this function.

Returns
A Time object representing the elapsed CPU time.
double jem::util::CPUTimer::toDouble ( ) const

Returns the elapsed CPU time in seconds as a double precision number. The current state of this timer is not affected by this function.

Returns
this->time().toDouble()
void jem::util::CPUTimer::start ( )

Switches this timer to the running state. If it was already in the running state, this functions does nothing.

Postcondition
this->isRunning() == true
void jem::util::CPUTimer::stop ( )

Switches this timer to the stopped state. If it was already in the stopped state, this function does nothing. Note that the measured CPU time so far is not reset.

Postcondition
this->isRunning() == false
void jem::util::CPUTimer::reset ( )

Sets the elapsed CPU time to zero. Calling this function does not affect the state of this CPUTimer.

Postcondition
this->time() == Time::zero()
bool jem::util::CPUTimer::isRunning ( ) const

Tests whether this timer is in the running state. Calling this function does not affect the state of this timer.

Returns
true if this timer is in the running state, and false otherwise.
static Time jem::util::CPUTimer::resolution ( )
static

Returns the resolution of a CPU timer.

Returns
A Time object representing the resolution of a CPUTimer.

Friends And Related Function Documentation

io::DataInput & operator> > ( io::DataInput in,
CPUTimer t 
)
related

Restores the state of the CPU timer t from the data input stream in.

Parameters
in- a data input stream.
t- the CPUTimer to be read from the input stream.
Returns
in.
Exceptions
IOException- if an I/O error occurs.
io::DataOutput & operator<< ( io::DataOutput out,
const CPUTimer t 
)
related

Writes the state of the CPU timer t to the data output stream out. The state of the timer can be restored at a later time by calling the de-serialization operator.

Parameters
out- data output stream.
t- the CPUTimer to be written to the output stream.
Returns
out.
Exceptions
IOException- if an I/O error occurs.
io::TextOutput & operator<< ( io::TextOutput out,
const CPUTimer t 
)
related

Prints the elapsed CPU time measured by the CPU timer t to the text output stream out.

Parameters
out- a text output stream.
t- the CPUTimer to be printed.
Returns
out.
Exceptions
IOException- if an I/O error occurs.
void swap ( CPUTimer lhs,
CPUTimer rhs 
)
related

This function is equivalent with:

lhs.swap( rhs )

Parameters
lhs- a CPUTimer instance.
rhs- another CPUTimer instance.