Mayothi Timer

Moyothi timer is a precision timer for C++ programs to measure events in microseconds. It also has a wait function, which differs from the normal sleep() function in that your program can still process messages while waiting.

The timer function is very simple and uses the QueryPerformanceCounter() and QueryPerformanceFrequency() functions to return the time measured with your PC’s high-resolution performance counter. On my PC the frequency of the counter is 3.579MHz, which gives a resolution of 1/3.579e6 = 0.28 microseconds.

The timer function is very simple and uses the QueryPerformanceCounter() and QueryPerformanceFrequency() functions to return the time measured with your PC’s high-resolution performance counter. On my PC the frequency of the counter is 3.579MHz, which gives a resolution of 1/3.579e6 = 0.28 microseconds.

Here is an example of using the timer:

#include “MTimer.cpp”

void main(void)
{
MTimer timer;

timer.start(); //start timer

//do stuff

unsigned long elapsed = timer.stop(); //stop timer

printf(“Time elapsed:%u uS\n”,elapsed); //shows the time elapsed in microseconds

}

Download MTimer

The downloaded file includes an example of using the timer (compiled in C++ builder.)

File: MTimer.zip (5Kb)