Public Member Functions | Static Public Member Functions

BlockTimer Class Reference
[Auxilliary Tools]

Auxilliary Tool: A class for tracking the absolute runtime of several (possibly overlapping) blocks of code. More...

#include <BlockTimer.h>

List of all members.

Public Member Functions

 BlockTimer (int numblocks=100)
 Constructor: Create a new set of stopwatches to time blocks of code.
void blockStart (int block)
 Cause a stopwatch to begin incrementing. This will begin increasing both the current time and the total time.
void blockStop (int block)
 Cause a stopwatch to stop incrementing. This will freeze the total time and reset the current time to 0.
void blockReset (int block)
 Cause a stopwatch to reset. This will set both the current time and the total time to 0.
void blockRestart (int block)
 Calls blockReset(block) and then blockStart(block).
double getCurrTime (int block)
 Get a stopwatch's current time, in seconds. Current time is amount of time from when it was last started until (1) now, or (2) it was stopped. If the stopwatch has not been started since it was reset, the current time is 0.
double getTotTime (int block)
 Get a stopwatch's total time, in seconds. Total time is amount of time that the stopwatch has been running since it was last reset. If the stopwatch has not been started since it was reset, the current time is 0.
 ~BlockTimer ()
 Simple Desturctor. Frees all memory associated with the set of timers.

Static Public Member Functions

static timertype getCurrentTimeInMicroseconds ()
 Use BSD standard system libraries and C-standard libraries to get the system current time in microseconds.

Detailed Description

Auxilliary Tool: A class for tracking the absolute runtime of several (possibly overlapping) blocks of code.

The basic philosophy of the BlockTimer class is that we want to arbitrarily invoke (start/stop/reset) several stop watches, each of which should have reasonable time precision ( < 1 ms) across several platforms. So at any time, one can start stopwatch 3, stop stopwatch 1, and reset stopwatch 42. We track time using the posix-standard functions "gettimeofday" and "localtime" to track the elapsed number of microseconds.

The basic operations of a timer are:

The basic readouts of a timer are:

Author:
Nicholas Butko
Date:
2010 version 0.4

Constructor & Destructor Documentation

BlockTimer::BlockTimer ( int  numblocks = 100 )

Constructor: Create a new set of stopwatches to time blocks of code.

Parameters:
numblocksAn initial guess at the maximum number of stopwatches you will need. This is for memory allocation. If you attempt to access a stopwatch with a greater index than you have memory for, more memory will be allocated at that time.

Member Function Documentation

void BlockTimer::blockReset ( int  block )

Cause a stopwatch to reset. This will set both the current time and the total time to 0.

Parameters:
blockThe index of the stopwatch to reset (indexed from 0->N-1).
void BlockTimer::blockRestart ( int  block )

Calls blockReset(block) and then blockStart(block).

Parameters:
blockThe index of the stopwatch to start (indexed from 0->N-1).
void BlockTimer::blockStart ( int  block )

Cause a stopwatch to begin incrementing. This will begin increasing both the current time and the total time.

Parameters:
blockThe index of the stopwatch to start (indexed from 0->N-1).
void BlockTimer::blockStop ( int  block )

Cause a stopwatch to stop incrementing. This will freeze the total time and reset the current time to 0.

Parameters:
blockThe index of the stopwatch to stop (indexed from 0->N-1).
timertype BlockTimer::getCurrentTimeInMicroseconds (  ) [static]

Use BSD standard system libraries and C-standard libraries to get the system current time in microseconds.

Specifically, this uses gettimeofday, time, and localtime. These are expected to be located in <sys/time.h> and <time.h>. If the compiler gives you trouble, try "man gettimeofday", "man time", and "man localtime" to figure out what headers you should use on your system, and include them in BlockTimer.cpp.

double BlockTimer::getCurrTime ( int  block )

Get a stopwatch's current time, in seconds. Current time is amount of time from when it was last started until (1) now, or (2) it was stopped. If the stopwatch has not been started since it was reset, the current time is 0.

Parameters:
blockThe index of the stopwatch (indexed from 0->N-1).
double BlockTimer::getTotTime ( int  block )

Get a stopwatch's total time, in seconds. Total time is amount of time that the stopwatch has been running since it was last reset. If the stopwatch has not been started since it was reset, the current time is 0.

Parameters:
blockThe index of the stopwatch (indexed from 0->N-1).

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