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...
 

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 86 of file timer.h.

Member Typedef Documentation

typedef long long Timer::ticks_t

Definition at line 88 of file timer.h.

Member Enumeration Documentation

Enumerator
DontPrintDtr 
PrintDtr 

Definition at line 90 of file timer.h.

Enumerator
DontStartNow 
StartNow 

Definition at line 89 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 94 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 108 of file timer.h.

Timer::~Timer ( )
inline

Destructor.

Definition at line 120 of file timer.h.

Member Function Documentation

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 173 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 160 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 182 of file timer.h.

void Timer::reset ( void  )
inline

Reset at zero and stop ticking.

Definition at line 151 of file timer.h.

static double Timer::seconds ( ticks_t  ticks)
inlinestatic

Convert number of ticks to seconds.

Definition at line 196 of file timer.h.

void Timer::start ( )
inline

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

Definition at line 128 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 139 of file timer.h.

bool Timer::ticking ( ) const
inline

Is the timer currently ticking?

Definition at line 199 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 177 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 186 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 193 of file timer.h.

Friends And Related Function Documentation

friend class TimerSetupOnce
friend

Definition at line 239 of file timer.h.


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