Search Tools Links Login

Nick of time

Posted: 2002-06-01
By: ArchiveBot
Viewed: 67

Filed Under:

VB6 Code Cache

Title Uploaded Size
Nick of 9/3/2020 3:45:00 PM 30,301

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

Original Author: Cakkie


If you think that the most accurate interval you can get is 1 ms, think again.

This article shows you how you can wait a very short time.

How short, well, on my PC (500mHz,128MB) i got an average of 0.0078 ms!

The trick is to make use of a high frequency performance counter wich nowaday
almost all computers have.

To do this, you must make use of the QueryPerformanceCount API (QPC). This give you a number.

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.

Using that value, you can determin how much time has expired.

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.

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

After this, you will never want to use gettickcount again

Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.