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

Measures the elapsed wall-clock time. More...

#include <jem/util/Timer.h>

Public Member Functions

 Timer ()
 Creates a new timer. More...
 
void swap (Timer &rhs)
 Interchanges the internal state of two timers. More...
 
Time time () const
 Returns the elapsed wall-clock time. More...
 
double toDouble () const
 Returns the elapsed wall-clock time in seconds as a double. More...
 
void start ()
 Starts this timer. More...
 
void stop ()
 Stops this timer. More...
 
void reset ()
 Sets the elapsed wall-clock 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 timer. More...
 

Related Functions

(Note that these are not member functions.)

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

Detailed Description

The class Timer can be used to measure the duration of an event in terms of the elapsed wall-clock time. A Timer 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, CPUTimer.
Examples:
alloc.cpp, Database.cpp, DataParser.cpp, and System.cpp.

Constructor & Destructor Documentation

jem::util::Timer::Timer ( )

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

Postcondition
this->isRunnable() == true

Member Function Documentation

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

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

Parameters
rhs- a Timer object.
Time jem::util::Timer::time ( ) const

Returns a Time object representing the wall-clock 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 wall-clock time.
double jem::util::Timer::toDouble ( ) const

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

Returns
this->time().toDouble()
Examples:
alloc.cpp, and System.cpp.
void jem::util::Timer::start ( )

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

Postcondition
this->isRunning() == true
Examples:
alloc.cpp, and System.cpp.
void jem::util::Timer::stop ( )

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

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

Sets the elapsed wall-clock time to zero. Calling this function does not affect the state of this timer.

bool jem::util::Timer::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::Timer::resolution ( )
static

Returns the resolution of a timer.

Returns
A Time instance representing the resolution of a Timer.

Friends And Related Function Documentation

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

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

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

Writes the state of the imer 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 Timer to be written to the output stream.
Returns
out.
Exceptions
IOException- if an I/O error occurs.
io::TextOutput & operator<< ( io::TextOutput out,
const Timer t 
)
related

Prints the elapsed wall-clock time measured by the timer t to the text output stream out.

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

This function is equivalent with:

lhs.swap( rhs )

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