Measures the elapsed wall-clock time.
More...
#include <jem/util/Timer.h>
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.
jem::util::Timer::Timer |
( |
| ) |
|
Creates a Timer
in the stopped state with the elapsed time initialized to zero.
- Postcondition
this->isRunnable() == true
void jem::util::Timer::swap |
( |
Timer & |
rhs | ) |
|
Interchanges the internal state of this timer with that of the rhs timer.
- Parameters
-
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
.
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. |
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. |
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. |
This function is equivalent with:
lhs.swap( rhs )
- Parameters
-
lhs | - a Timer instance. |
rhs | - another Timer instance. |