Introduction

This timer class is capable to measure time intervals in microseconds under Windows OS.
It is using the less known Windows API functions
QueryPerformanceFrequency() and QueryPerformanceCounter() for
getting the frequency and respectively the counts of the high-resolution performance counter. For systems
where such a high-resolution performance counter is not available, the more
known API function GetTickCounts() is used instead,
but with a performance penalty on the timer's precision. The reliability of the timer is depending anyway on the system's
hardware performance, i.e. the accuracy is increased for systems with higher processor frequency. The class is
also demonstrating some useful tips about using the __int64 integers in VC++.

Implementation

Here I present only the public user interface of the CPreciseTimer class, the implementation details being in the
demo project source files:

The constructor CPreciseTimer() at the first class's instance construction is also determining if the
high-resolution performance counter is available, and in the favorable case is initializing the frequency
member variable. Subsequent constructions are not repeating this computation block.

The function SupportsHighResCounter() is returning true only
if the high-resolution performance counter is available.
It is giving to the user a clue about the accuracy of the timer.

The function StartTimer(), as the name says, is starting the timer.

The function StopTimer() is stopping the timer, also keeping the elapsed time since the timer was started.

The function GetTime() in case the timer is in the running state is returning the time interval
since the timer was started. If the timer is in the stopped state then it is returning the time difference
between the last stop call and the last start call. The returned value is in microseconds, but it cannot be trusted
if the high-resolution performance counter is not available, case for which the accuracy cannot be in fact
higher than the order of milliseconds.