sxTimer Class Reference

Timer with microsecond resolution. More...

#include <sxTimer.h>

Inheritance diagram for sxTimer:

sxObject

List of all members.

Public Member Functions

 sxTimer ()
 Construct timer object.
 sxTimer (const sxTimer &ot)
 sxTimer (qint64 b)
sxTimeroperator= (const sxTimer &ot)
void Start ()
 Start the timer.
qint64 uElapsed () const
 Elapsed time in usec since started.
int mElapsed () const
qint64 Tic ()
 Start stopwatch function.
qint64 uToc () const
 Get elapsed time in microsecond(s) since Tic() called.
double mToc () const
 Get elapsed time in milisecond(s) since Tic() called.
double Toc () const
 Get elapsed time in second(s) since Tic() called.
qint64 Base () const
 Based of the timer object.

Static Public Member Functions

static qint64 now ()
 Calculate current time stamp (in microseconds).
static void uwait2 (unsigned int usec, bool *cancel=0)
 Block the execution for given microsecond(s).
static void uwait (unsigned int usec)
static void mwait (unsigned int msec)
 Block the execution for given millisecond(s).
static void idle ()
 Idle for a moment.


Detailed Description

Timer with microsecond resolution.

This utility class for timer/stopwatch related function. Here is an example of how to using the class.
1) Measuring execution time

    sxTimer timer;
    timer.Tic();
    //do some processing
    tm = timer.Toc();  //calculated elapsed second(s).
2) Sleeping/waiting for a specific micro/millisecond(s)
    sxTimer::mwait(10); //wait for 10 milliseconds

    //wait for 100 microsecond(s) with cancelable thread.
    //this mainly for multithreading
    bool flag;
    sxTimer::uwait(100, &flag);

Constructor & Destructor Documentation

sxTimer::sxTimer (  ) 

Construct timer object.

The timer based will be initialized with current time stamp.

See also:
Start()

References Start().


Member Function Documentation

void sxTimer::idle (  )  [static]

Idle for a moment.

In windows, this function call Sleep(0)

double sxTimer::mToc (  )  const

Get elapsed time in milisecond(s) since Tic() called.

Returns:
msec in double format
See also:
Tic(), uToc(), Toc()

References uElapsed().

void sxTimer::mwait ( unsigned int  msec  )  [static]

Block the execution for given millisecond(s).

Parameters:
msec number of millisecond to wait

References now().

qint64 sxTimer::now (  )  [static]

Calculate current time stamp (in microseconds).

This function in win32 using QueryPerformanceCounter and QueryPerformanceFrequency. In linux/unix, using gettimeofday.

Referenced by mwait(), Start(), uElapsed(), and uwait2().

void sxTimer::Start (  ) 

Start the timer.

Based of this timer object will be initialized with current time-stamp.

See also:
now()

References now().

Referenced by sxTimer(), and Tic().

qint64 sxTimer::Tic (  ) 

Start stopwatch function.

This call usually followed by xToc().

See also:
Start(), Toc(), mToc(), uToc()

References Start().

double sxTimer::Toc (  )  const

Get elapsed time in second(s) since Tic() called.

Returns:
sec in double format
See also:
Tic(), uToc(), mToc()

References uElapsed().

qint64 sxTimer::uElapsed (  )  const

Elapsed time in usec since started.

Returns:
number of usec in 64-bit integer

References now().

Referenced by mToc(), Toc(), and uToc().

qint64 sxTimer::uToc (  )  const

Get elapsed time in microsecond(s) since Tic() called.

Returns:
microsec in 64-bit integer
See also:
Tic(), uToc(), mToc()

References uElapsed().

void sxTimer::uwait2 ( unsigned int  usec,
bool *  cancel = 0 
) [static]

Block the execution for given microsecond(s).

Parameters:
usec number of microsecond to sleep
cancel pointer to cancel flag

References now().


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

Generated on Wed Dec 17 19:30:47 2008 for xBCI API by  doxygen 1.5.7.1