Loading...
Searching...
No Matches
casacore::Timer Class Reference
casa package (libcasa_casa) » OS_module

More...

`#include <Timer.h>`

## Public Member Functions

| Timer ()
| Construct a timer and set the mark ("mark()").
void | mark ()
| Set the timer mark – i.e., start the clock ticking.
double | user () const
| Get the user time (in seconds) since last "mark()".
double | system () const
| Get the system time (in seconds) since last "mark()".
double | all () const
| Get the user+system time (in seconds) since last "mark()".
double | real () const
| Get the real time (in seconds) since last "mark()".
void | show () const
| Show real, user, system time (in seconds) on cout or a user supplied stream.
void | show (ostream &os) const
void | show (const String &) const
| Show real, user, system time (in seconds) on cout or a user supplied stream preceeded by the string parameter.
void | show (ostream &os, const String &prefix) const
double | user_usec () const
| Get the user time (in microseconds) since last "mark()".
double | system_usec () const
| Get the system time (in microseconds) since last "mark()".
double | all_usec () const
| Get the user+system time (in microseconds) since last "mark()".

## Private Attributes

rusage | usage0
timeb | real0

## Detailed Description

measure the time it takes to execute parts of a program

### Intended use:

Public interface

### Review Status

Reviewed By:
  Paul Shannon
Date Reviewed:
  1995/03/01/

### Synopsis

The Timer class provides an interface to system timing. It allows a C++ program to record the time between a reference point (mark) and now. This class uses the system time(2) interface to provide time resolution at either millisecond or microsecond granularity, depending upon operating system support and features. Since the time duration is stored in a 32-bit word, the maximum time period before rollover occurs is about 71 minutes.

Due to operating system dependencies, the accuracy of all member function results may not be as documented. For example some operating systems do not support timers with microsecond resolution. In those cases, the values returned are provided to the nearest millisecond or other unit of time as appropriate. See the Timer header file for system- specific notes.

Tip: This Timer class is based on the TI COOL library Timer class

### Example

Here's how to create a timer, start it (the 'mark' member function) and display a breakdown. Recall that

realtime = user time + system time
casacore::Timer::system
double system() const
Get the system time (in seconds) since last "mark()".
casacore::Timer::user
double user() const
Get the user time (in seconds) since last "mark()".
casacore::time
TableExprNode time(const TableExprNode &node)
Definition ExprNode.h:1584
Timer timer; // the mark is set at construction time
timer.mark(); // if you want to restart the clock
...do some calculation..\.
cout << "user: " << timer.user () << endl;
cout << "system: " << timer.system () << endl;
cout << "real: " << timer.real () << endl;
casacore::Timer::mark
void mark()
Set the timer mark – i.e., start the clock ticking.
casacore::Timer::real
double real() const
Get the real time (in seconds) since last "mark()".
casacore::Timer::Timer
Timer()
Construct a timer and set the mark ("mark()").
Definition Timer.h:130

### To Do

- it might be useful to have a stop () member function: for really precise timing, the successive calls to user, system and real all happen at measurably different times
- provide an enquiry function that reports the resolution of the timer

- add 'start' member function, a synonym for 'mark' but more comprehensible

Definition at line 125 of file Timer.h.

## Constructor & Destructor Documentation

## Timer()

casacore::Timer::Timer | ( |  | ) |

inline

Construct a timer and set the mark ("mark()").

Definition at line 130 of file Timer.h.

References mark().

## Member Function Documentation

## all()

double casacore::Timer::all | ( |  | ) | const

Get the user+system time (in seconds) since last "mark()".

## all_usec()

double casacore::Timer::all_usec | ( |  | ) | const

Get the user+system time (in microseconds) since last "mark()".

References real0, and usage0.

## mark()

void casacore::Timer::mark | ( |  | ) |

Set the timer mark – i.e., start the clock ticking.

Referenced by Timer().

## real()

double casacore::Timer::real | ( |  | ) | const

Get the real time (in seconds) since last "mark()".

## show() [1/4]

void casacore::Timer::show | ( |  | ) | const

Show real, user, system time (in seconds) on cout or a user supplied stream.

## show() [2/4]

void casacore::Timer::show | ( | const String & |  | ) | const

Show real, user, system time (in seconds) on cout or a user supplied stream preceeded by the string parameter.

## show() [3/4]

void casacore::Timer::show | ( | ostream & | os | ) | const

## show() [4/4]

void casacore::Timer::show | ( | ostream & | os,
|  | const String & | prefix ) const

## system()

double casacore::Timer::system | ( |  | ) | const

Get the system time (in seconds) since last "mark()".

## system_usec()

double casacore::Timer::system_usec | ( |  | ) | const

Get the system time (in microseconds) since last "mark()".

## user()

double casacore::Timer::user | ( |  | ) | const

Get the user time (in seconds) since last "mark()".

## user_usec()

double casacore::Timer::user_usec | ( |  | ) | const

Get the user time (in microseconds) since last "mark()".

## Member Data Documentation

## real0

timeb casacore::Timer::real0

private

Definition at line 201 of file Timer.h.

Referenced by all_usec().

## usage0

rusage casacore::Timer::usage0

private

Definition at line 200 of file Timer.h.

Referenced by all_usec().

The documentation for this class was generated from the following file:

- casa/OS/Timer.h