HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Timer Class Reference

#include <timer.h>

Public Types

enum  StartNowVal { DontStartNow, StartNow }
 
enum  PrintDtrVal { DontPrintDtr, PrintDtr }
 
typedef long long ticks_t
 

Public Member Functions

 Timer (StartNowVal startnow=StartNow, PrintDtrVal printdtr=DontPrintDtr, const char *name=NULL)
 
 Timer (bool startnow)
 
 ~Timer ()
 Destructor. More...
 
void start ()
 Start (or restart) ticking, if we are not currently. More...
 
double stop ()
 
void reset (void)
 
ticks_t lap_ticks ()
 
double lap ()
 
ticks_t ticks () const
 
double operator() (void) const
 
ticks_t ticks_since_start (void) const
 
double time_since_start (void) const
 
bool ticking () const
 Is the timer currently ticking? More...
 
void add_ticks (ticks_t delta)
 
void add_seconds (double t)
 

Static Public Member Functions

static double seconds (ticks_t ticks)
 Convert number of ticks to seconds. More...
 

Friends

class TimerSetupOnce
 

Detailed Description

Simple timer class.

This class allows you to time things, for runtime statistics and the like. The simplest usage pattern is illustrated by the following example:

Timer mytimer; // automatically starts upon construction
...do stuff
float t = mytimer(); // seconds elapsed since start
Timer another (false); // false means don't start ticking yet
another.start (); // start ticking now
another.stop (); // stop ticking
another.start (); // start again where we left off
another.stop ();
another.reset (); // reset to zero time again

These are not very high-resolution timers. A Timer begin/end pair takes somewhere in the neighborhood of 0.1 - 0.3 us (microseconds), and can vary by OS. This means that (a) it's not useful for timing individual events near or below that resolution (things that would take only tens or hundreds of processor cycles, for example), and (b) calling it millions of times could make your program appreciably more expensive due to the timers themselves.

Definition at line 61 of file timer.h.

Member Typedef Documentation

typedef long long Timer::ticks_t

Definition at line 63 of file timer.h.

Member Enumeration Documentation

Enumerator
DontPrintDtr 
PrintDtr 

Definition at line 65 of file timer.h.

Enumerator
DontStartNow 
StartNow 

Definition at line 64 of file timer.h.

Constructor & Destructor Documentation

Timer::Timer ( StartNowVal  startnow = StartNow,
PrintDtrVal  printdtr = DontPrintDtr,
const char *  name = NULL 
)
inline

Constructor – reset at zero, and start timing unless optional 'startnow' argument is false.

Definition at line 69 of file timer.h.

Timer::Timer ( bool  startnow)
inline

Constructor – reset at zero, and start timing unless optional 'startnow' argument is false.

Definition at line 83 of file timer.h.

Timer::~Timer ( )
inline

Destructor.

Definition at line 95 of file timer.h.

Member Function Documentation

void Timer::add_seconds ( double  t)
inline

Force an offset to the total, in seconds. This value may be negative to subtract from the total. To avoid disrupting the timer in progress, this is added to the total elapsed time but not to the current lap, so it will be reflected in ticks() or seconds(), but will NOT be reflected in ticks_since_start() or time_since_start().

Definition at line 188 of file timer.h.

void Timer::add_ticks ( ticks_t  delta)
inline

Force an offset to the total, in ticks. This value may be negative to subtract from the total. To avoid disrupting the timer in progress, this is added to the total elapsed time but not to the current lap, so it will be reflected in ticks() or seconds(), but will NOT be reflected in ticks_since_start() or time_since_start().

Definition at line 181 of file timer.h.

double Timer::lap ( )
inline

Return just the time of the current lap (since the last call to start() or lap()), add that to the previous elapsed time, reset current start time to now, keep the timer going (if it was).

Definition at line 148 of file timer.h.

ticks_t Timer::lap_ticks ( )
inline

Return just the ticks of the current lap (since the last call to start() or lap()), add that to the previous elapsed time, reset current start time to now, keep the timer going (if it was).

Definition at line 135 of file timer.h.

double Timer::operator() ( void  ) const
inline

Operator () returns the elapsed time so far, in seconds, including both the currently-ticking clock as well as any previously elapsed time.

Definition at line 157 of file timer.h.

void Timer::reset ( void  )
inline

Reset at zero and stop ticking.

Definition at line 126 of file timer.h.

static double Timer::seconds ( ticks_t  ticks)
inlinestatic

Convert number of ticks to seconds.

Definition at line 171 of file timer.h.

void Timer::start ( )
inline

Start (or restart) ticking, if we are not currently.

Definition at line 103 of file timer.h.

double Timer::stop ( )
inline

Stop ticking, return the total amount of time that has ticked (both this round as well as previous laps). Current ticks will be added to previous elapsed time.

Definition at line 114 of file timer.h.

bool Timer::ticking ( ) const
inline

Is the timer currently ticking?

Definition at line 174 of file timer.h.

ticks_t Timer::ticks ( ) const
inline

Total number of elapsed ticks so far, including both the currently- ticking clock as well as any previously elapsed time.

Definition at line 152 of file timer.h.

ticks_t Timer::ticks_since_start ( void  ) const
inline

Return just the ticks since we called start(), not any elapsed time in previous start-stop segments.

Definition at line 161 of file timer.h.

double Timer::time_since_start ( void  ) const
inline

Return just the time since we called start(), not any elapsed time in previous start-stop segments.

Definition at line 168 of file timer.h.

Friends And Related Function Documentation

friend class TimerSetupOnce
friend

Definition at line 229 of file timer.h.


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