|Windows with Delphi|
Windows API (94)
Windows Filesystem (41)
Windows Forms (69)
Windows Graphics (38)
About this site
Links to us
QueryPerformanceCounter() vs. GetTickCount()
1 comments. Current rating: (1 votes). Leave comments and/ or rate it.
QueryPerformanceCounter() uses the PC's clock counter just as GetTickCount(), but it reads the current value of the countdown register in the timer chip to gain more accuracy -- down to 1.193MHz (about 800ns).
However, it takes 5 to 10us to call QueryPerformanceCounter, because it has to do several port I/O instructions to read this value.
If you are running multiprocessor NT, QueryPerformanceCounter uses the Pentium cycle counter.
You should not be using the raw value of QueryPerformanceCounter; you should always divide by QueryPerformanceFrequency to convert to some known time base. QueryPerformanceCounter doesn't run at the same rate on all machines.
The example below shows how to use it in Delphi 3/4:
TInt64 = TLargeInteger;
Frequency, lpPerformanceCount1, lpPerformanceCount2 : TLargeInteger;
ShowMessage(IntToStr(Round(1000000 * (lpPerformanceCount2.QuadPart -
lpPerformanceCount1.QuadPart) / Frequency.QuadPart)));