casa
5.7.0-16
|
Precision timer to measure elapsed times in a cumulative way. More...
#include <PrecTimer.h>
Classes | |
struct | TimeStruct |
union | Union1 |
struct | Union2 |
Public Member Functions | |
PrecTimer () | |
Construct. More... | |
~PrecTimer () | |
Destruct. More... | |
void | start () |
Restart the timer. More... | |
void | stop () |
Stop the timer. More... | |
void | reset () |
Reset the timer to zero. More... | |
void | show () const |
Show real time on cout or a user supplied stream. More... | |
void | show (std::ostream &os) const |
void | show (const String &) const |
Show real time on cout or a user supplied stream preceeded by the string parameter. More... | |
void | show (std::ostream &os, const String &prefix) const |
double | getReal () const |
Get the real time (in seconds). More... | |
unsigned long long | getCount () const |
Get the total number of times start/stop is done. More... | |
Private Member Functions | |
void | print_time (std::ostream &, double time) const |
Static Private Member Functions | |
static double | get_CPU_speed_in_MHz () |
Private Attributes | |
Union1 | u1 |
Union2 | u2 |
Static Private Attributes | |
static double | CPU_speed_in_MHz |
Precision timer to measure elapsed times in a cumulative way.
Public interface
The PrecTimer supplements the Timer class. If offers a low-overhead and high-resolution interval timer for use on i386, x86_64, ia64, and powerpc platforms, using the processor's timestamp counter that is incremented each cycle. Put timer.start() and timer.stop() calls around the piece of code to be timed. Because the timer is cumulative, the total time of a particular piece of code can be timed.
Caution: Make sure that start() and stop() calls alternate, otherwise very strange times will be the result;
A timer can be started and stopped multiple times; both the average and total time, as well as the number of iterations are printed. The measured time is real time (as opposed to user or system time). The timer can be used to measure from 10 nanosecond to a century interval.
Multiple timers can be used in a nested way as long as each of them has independent (matching) start and stop calls.
The class is more or less a copy of the original written by John Romein at ASTRON, Dwingeloo, the Netherlands.
Here's how to create a timer, start it (the 'mark' member function) and display a breakdown.
Definition at line 101 of file PrecTimer.h.
|
inline |
|
inline |
Destruct.
Definition at line 190 of file PrecTimer.h.
|
staticprivate |
|
inline |
Get the total number of times start/stop is done.
Definition at line 180 of file PrecTimer.h.
References casacore::PrecTimer::Union2::count, and u2.
double casacore::PrecTimer::getReal | ( | ) | const |
Get the real time (in seconds).
|
private |
|
inline |
Reset the timer to zero.
Definition at line 174 of file PrecTimer.h.
References casacore::PrecTimer::Union2::count, casacore::PrecTimer::Union1::total_time, u1, and u2.
Referenced by PrecTimer().
void casacore::PrecTimer::show | ( | ) | const |
Show real time on cout or a user supplied stream.
void casacore::PrecTimer::show | ( | std::ostream & | os | ) | const |
void casacore::PrecTimer::show | ( | const String & | ) | const |
Show real time on cout or a user supplied stream preceeded by the string parameter.
void casacore::PrecTimer::show | ( | std::ostream & | os, |
const String & | prefix | ||
) | const |
|
inline |
Restart the timer.
Definition at line 194 of file PrecTimer.h.
References casacore::PrecTimer::Union1::s1, casacore::time(), casacore::PrecTimer::Union1::total_time, casacore::PrecTimer::TimeStruct::total_time_high, casacore::PrecTimer::TimeStruct::total_time_low, and u1.
|
inline |
Stop the timer.
Definition at line 268 of file PrecTimer.h.
References casacore::PrecTimer::Union2::count, casacore::PrecTimer::Union1::s1, casacore::time(), casacore::PrecTimer::Union1::total_time, casacore::PrecTimer::TimeStruct::total_time_high, casacore::PrecTimer::TimeStruct::total_time_low, u1, and u2.
|
staticprivate |
Definition at line 168 of file PrecTimer.h.
|
private |
Definition at line 165 of file PrecTimer.h.
|
private |
Definition at line 166 of file PrecTimer.h.
Referenced by getCount(), reset(), and stop().