DelphiFAQ Home Search:

QueryPerformanceCounter() vs. GetTickCount()


comments1 comments. Current rating: 4 stars (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;


  // activity to measure

  // this shows the time in ns
  ShowMessage(IntToStr(Round(1000000 * (lpPerformanceCount2.QuadPart -
                       lpPerformanceCount1.QuadPart) / Frequency.QuadPart)));


2010-03-08, 23:40:42
anonymous from Mauritius  




NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: