Advertisement
2002VB Windows API Call/ Explanation #22743

Nick of time

Take control over time, howto get a better frequency than 1 millisecond.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
If you think that the most accurate interval you can get is 1 ms, think again.
<br>This article shows you how you can wait a very short time.
<p>
How short, well, on my PC (500mHz,128MB) i got an average of 0.0078 ms!
<br>The trick is to make use of a high frequency performance counter wich nowaday
almost all computers have.
<p>
To do this, you must make use of the QueryPerformanceCount API (QPC). This give you a number.
<br>This number is the current count of the timer. When you use the QueryPerformanceFrequency (QPF) API, you will get the number of times that the timer counts per second.
<br>Using that value, you can determin how much time has expired.
<p>
Example: if your frequency = 1.000.000 and the difference between 2 calls of the QPC is 1.000, you know that the time elapsed is 1.000 / 1.000.000 = 0.001 seconds.
<p>
The example included (see zip) also show that the GetTickCount API isn't as fast as you may think. I got a accuricy of +/- 10 ms
<p>
After this, you will never want to use gettickcount again
Original Comments (3)
Recovered from Wayback Machine