DWFCore::DWFTimer Class Reference
[Platform-specific Class and Function Definitions]

#include "dwfcore/Timer.h"

Inheritance diagram for DWFCore::DWFTimer:

Inheritance graph
[legend]
Collaboration diagram for DWFCore::DWFTimer:

Collaboration graph
[legend]
List of all members.

Detailed Description

This class provides a high resolution hardware-based timer.

Since:
1.0.1
Note:
This class has platform-specific implementations.
This class most basically provides access to a raw cpu tick count. Using this 64-bit value, it then provides simple stopwatch-like functionality for measuring code execution. Since the class declaration is the same for all platforms, it (and the values it provides) can be used in portable code. Further, these values are more accurate for measuring events that occur under the millisecond threshhold where using certain OS-specific APIs would not suffice. It is preferrable to use these numbers and convert them into milliseconds (or some other unit) if the need arises. The following sample is one such method:

Example - convert high resultion cpu ticks into milliseconds:

                            cout << "Calibrating...";
   
                    #ifdef  _DWFCORE_WIN32_SYSTEM
   
                            unsigned long ms = ::GetTickCount();
                            unsigned long long ts = DWFTimer::Tick64();
                            ::Sleep( 1000 );
                            ts = DWFTimer::Tick64() - ts;
                            ms = ::GetTickCount() - ms;
   
                            double tpms = ts/(double)(ms);
                    #else
   
                            struct timeval tv;
                            struct timeval tv2;
                            gettimeofday( &tv, NULL );
                            unsigned long long ts = DWFTimer::Tick64();
                            usleep( 10000 );
                            ts = DWFTimer::Tick64() - ts;
                            gettimeofday( &tv2, NULL );
   
                            time_t sec = tv2.tv_sec - tv.tv_sec;
                            suseconds_t usec = tv2.tv_usec - tv.tv_usec;
   
                            double tpms = ts/( (sec*1000) + (usec/1000) );
                   #endif
   
                            cout << "using " << tpms << " ticks per ms" << endl << endl;

Definition at line 88 of file Timer.h.

Public Member Functions

_DWFCORE_API DWFTimer () throw ()
_DWFCORE_API DWFTimer (const DWFTimer &rTimer) throw ()
_DWFCORE_API DWFTimeroperator= (const DWFTimer &rTimer) throw ()
_DWFCORE_API ~DWFTimer () throw ()
_DWFCORE_API void start () throw ()
_DWFCORE_API unsigned long tick32 () throw ()
_DWFCORE_API uint64_t tick64 () throw ()
_DWFCORE_API void stop () throw ()
_DWFCORE_API unsigned long timer32 () throw ()
_DWFCORE_API uint64_t timer64 () throw ()

Static Public Member Functions

static _DWFCORE_API unsigned
long 
Tick32 () throw ()
static _DWFCORE_API uint64_t Tick64 () throw ()


Constructor & Destructor Documentation

_DWFCORE_API DWFCore::DWFTimer::DWFTimer  )  throw ()
 

Constructor

Exceptions:
None 

_DWFCORE_API DWFCore::DWFTimer::DWFTimer const DWFTimer rTimer  )  throw ()
 

Copy Constructor

Parameters:
rTimer The other timer from which to copy the tick value.
Exceptions:
None 

_DWFCORE_API DWFCore::DWFTimer::~DWFTimer  )  throw ()
 

Destructor

Exceptions:
None 


Member Function Documentation

_DWFCORE_API DWFTimer& DWFCore::DWFTimer::operator= const DWFTimer rTimer  )  throw ()
 

Assignment Operator

Parameters:
rTimer The other timer from which to copy the tick value.
Exceptions:
None 

_DWFCORE_API void DWFCore::DWFTimer::start  )  throw ()
 

Begins the timer/stopwatch feature of the class. This method should be can in conjuction with stop(), tick32(), tick64(), timer32() and timer64().

Stopwatch Example:

                    DWFTimer oStopwatch;
                    uint64_t nLastLap = 0;
                    
                    oStopwatch.start();
       
                    for(int i = 0; i < LAPS; i++)
                    {
                        ... do work ...
                    
                        uint64_t nLap = oStopwatch.tick64();
                        record_lap_time( i, nLap - nLastLap );
                        nLastLap = nLap;
                    }
       
                    oStopwatch.stop();
                    record_total_time( oStopwatch.timer64() );

Exceptions:
None 

_DWFCORE_API void DWFCore::DWFTimer::stop  )  throw ()
 

Stops the timer and stores the elapsed difference from the last start() call.

Exceptions:
None 

_DWFCORE_API unsigned long DWFCore::DWFTimer::tick32  )  throw ()
 

Returns the lower 32-bit difference from the last start() call.

Returns:
The difference in cpu tick values.
Exceptions:
None 

static _DWFCORE_API unsigned long DWFCore::DWFTimer::Tick32  )  throw () [static]
 

Returns the lower 32-bits of the cpu tick.

Returns:
The cpu tick value.
Exceptions:
None 

_DWFCORE_API uint64_t DWFCore::DWFTimer::tick64  )  throw ()
 

Returns the full 64-bit difference from the last start() call.

Returns:
The difference in cpu tick values.
Exceptions:
None 

static _DWFCORE_API uint64_t DWFCore::DWFTimer::Tick64  )  throw () [static]
 

Returns the full 64-bits of the cpu tick.

Returns:
The cpu tick value.
Exceptions:
None 

_DWFCORE_API unsigned long DWFCore::DWFTimer::timer32  )  throw ()
 

Returns the lower 32-bits of the ticks elapsed between start() and stop() calls.

Returns:
The difference in cpu tick values.
Exceptions:
None 

_DWFCORE_API uint64_t DWFCore::DWFTimer::timer64  )  throw ()
 

Returns the full 64-bits of the ticks elapsed between start() and stop() calls.

Returns:
The difference in cpu tick values.
Exceptions:
None 


The documentation for this class was generated from the following file:
Generated on Tue Jan 6 22:39:43 2009 for Autodesk DWF Core Library by  doxygen 1.4.5