Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

vrj::Timer Class Reference

Simple class to take timings and give averages. More...

#include <Timer.h>

List of all members.

Public Methods

 Timer ()
void startTiming ()
 Starts a timing. More...

void stopTiming ()
 Stops current timing. More...

double getTiming ()
 Gets the average timing. More...

double getLastTiming ()
long getTimeCount ()
 Returns the number of timings collected. More...

void reset ()
double wallclock ()


Detailed Description

Simple class to take timings and give averages.

Note:
All times are in seconds. XXX: Should use vpr::Interval for the time info in the future.

Definition at line 49 of file Timer.h.


Constructor & Destructor Documentation

vrj::Timer::Timer   [inline]
 

Definition at line 52 of file Timer.h.

References wallclock.

00053     {
00054         totalTime = 0;
00055         timeCount = 0;
00056         startTime = wallclock();
00057         endTime = startTime;
00058     }


Member Function Documentation

void vrj::Timer::startTiming   [inline]
 

Starts a timing.

Definition at line 61 of file Timer.h.

References wallclock.

00062     { startTime = wallclock(); }

void vrj::Timer::stopTiming   [inline]
 

Stops current timing.

Precondition:
Timing has been started.

Definition at line 68 of file Timer.h.

References wallclock.

00069     {
00070         endTime = wallclock();
00071         if (startTime == 0) // If we haven't called start then ignore
00072         { totalTime = 0; }
00073         else
00074         {
00075             lastTiming = (endTime - startTime);
00076             totalTime += lastTiming;
00077             timeCount++;
00078         }
00079     }

double vrj::Timer::getTiming   [inline]
 

Gets the average timing.

Definition at line 82 of file Timer.h.

00083     { return (totalTime/(double)timeCount); }

double vrj::Timer::getLastTiming   [inline]
 

Definition at line 85 of file Timer.h.

00086     { return lastTiming; }

long vrj::Timer::getTimeCount   [inline]
 

Returns the number of timings collected.

Definition at line 89 of file Timer.h.

00090     { return timeCount; }

void vrj::Timer::reset   [inline]
 

Definition at line 92 of file Timer.h.

References wallclock.

00093     {
00094         totalTime = 0;
00095         timeCount = 0;
00096         startTime = wallclock();
00097         endTime = startTime;
00098     }

double vrj::Timer::wallclock   [inline]
 

Definition at line 106 of file Timer.h.

Referenced by reset, startTiming, stopTiming, and Timer.

00107    {
00108        double v;
00109        struct timeval tv;
00110 
00111        vpr::System::gettimeofday(&tv);
00112 
00113        v = (double) tv.tv_sec + (double) tv.tv_usec / 1000000.0;
00114        return v;
00115    }


The documentation for this class was generated from the following file:
Generated on Sun May 2 15:11:16 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002