Jive reference manual
|
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::DataInput & | operator> > (io::DataInput &in, CPUTimer &t) |
De-serialization operator. More... | |
io::DataOutput & | operator<< (io::DataOutput &out, const CPUTimer &t) |
Serialization operator. More... | |
io::TextOutput & | operator<< (io::TextOutput &out, const CPUTimer &t) |
Print operator. More... | |
void | swap (CPUTimer &lhs, CPUTimer &rhs) |
Interchanges two CPU timers. More... | |
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.
jem::util::CPUTimer::CPUTimer | ( | ) |
Creates a CPUTimer
in the stopped state with the elapsed time initialized to zero.
thic->isRunning() == false
void jem::util::CPUTimer::swap | ( | CPUTimer & | rhs | ) |
Interchanges the internal state of this timer with that of the rhs timer.
rhs | - a CPUTimer instance. |
Time jem::util::CPUTimer::time | ( | ) | const |
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.
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.
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.
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
.
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.
true
if this timer is in the running state, and false
otherwise.
|
static |
|
related |
Restores the state of the CPU timer t from the data input stream in.
in | - a data input stream. |
t | - the CPUTimer to be read from the input stream. |
IOException | - if an I/O error occurs. |
|
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.
out | - data output stream. |
t | - the CPUTimer to be written to the output stream. |
IOException | - if an I/O error occurs. |
|
related |
Prints the elapsed CPU time measured by the CPU timer t to the text output stream out.
out | - a text output stream. |
t | - the CPUTimer to be printed. |
IOException | - if an I/O error occurs. |