STIR  6.2.0
Public Member Functions | Static Public Member Functions | List of all members
stir::HighResWallClockTimer Class Reference

High-resolution timer. More...

#include "stir/HighResWallClockTimer.h"

Public Member Functions

 HighResWallClockTimer (void)
 Create a timer. More...
 
virtual ~HighResWallClockTimer (void)
 Destroy a timer. More...
 
void start (bool bReset=false)
 Start a timer. More...
 
void stop (void)
 Stop a running timer. More...
 
void reset (void)
 Reset a timer. More...
 
bool is_running (void)
 Check if a timer is running. More...
 
int get_sec (void)
 Returns the number of whole seconds elapsed. More...
 
int get_nanosec (void)
 Returns the number of nanoseconds that elapsed on top of whatever get_sec() returned. More...
 
double value (void)
 Returns the elapsed time (in seconds) More...
 

Static Public Member Functions

static int get_resolution_in_nanosecs (void)
 Attempts to guess the timer resolution. More...
 

Detailed Description

High-resolution timer.

This timer measures wall-clock time. Implementation is OS specific to try to use high-resolution timers. It is not derived from stir::Timer to avoid the overhead of calling a virtual function.

Typical usage:
t.start();
do_something();
t.stop();
cout << "do_something took " << t.value() << " seconds" << endl;
t.start();
do_something_else();
t.stop();
cout << "total wall-clock time: " << t.value() << " seconds" << endl;

You have to call stop() before getting the value. You have to call reset() if you wish to use the same timer to measure several separate time intervals, otherwise the time will be accumulated.

Constructor & Destructor Documentation

◆ HighResWallClockTimer()

stir::HighResWallClockTimer::HighResWallClockTimer ( void  )
inline

Create a timer.

The timer is not started, and elapsed time is set to zero.

References reset().

◆ ~HighResWallClockTimer()

stir::HighResWallClockTimer::~HighResWallClockTimer ( void  )
inlinevirtual

Destroy a timer.

The timer must not be running.

Member Function Documentation

◆ start()

void stir::HighResWallClockTimer::start ( bool  bReset = false)
inline

◆ stop()

void stir::HighResWallClockTimer::stop ( void  )
inline

◆ reset()

void stir::HighResWallClockTimer::reset ( void  )
inline

◆ is_running()

bool stir::HighResWallClockTimer::is_running ( void  )
inline

Check if a timer is running.

Returns true if the timer is running, or false otherwise

◆ get_sec()

int stir::HighResWallClockTimer::get_sec ( void  )
inline

Returns the number of whole seconds elapsed.

The timer must not be running

Referenced by value().

◆ get_nanosec()

int stir::HighResWallClockTimer::get_nanosec ( void  )
inline

Returns the number of nanoseconds that elapsed on top of whatever get_sec() returned.

The timer must not be running

Referenced by value().

◆ value()

double stir::HighResWallClockTimer::value ( void  )
inline

◆ get_resolution_in_nanosecs()

int stir::HighResWallClockTimer::get_resolution_in_nanosecs ( void  )
inlinestatic

Attempts to guess the timer resolution.

get_resolution_in_nanosecs() is by no means accurate. The only thing that is guranteed is that timer resolution is not less than the value returned by get_resolution_in_nanosecs().

On Win32, returns more or less precise resolution (can be slightly rounded if the actual resolution can't be expressed as an integer number of nanoseconds)

Returns
Estimated timer resolution (in nanoseconds)

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