#### Archived

This topic is now archived and is closed to further replies.

# How to use QueryPerformance Counter/Frequency for timer?

This topic is 5615 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I want to use the QueryPerformance Counter/Frequency apis to create a timer. But in all the examples that I have seen, i get lost. So far I''ve made an extremely inaccurate timer timeGetTime. So with a function, like the one that i made before, it goes like this. bool Timer(int duration) so to use it I''d say: if (timer) dowhatever I want to do this with the QueryPerformance apis. So how would i do this. Could someone explain how these api''s work? or direct me to a website. Thanks.

##### Share on other sites
NeHe''s tutorial 21 makes use of a timer using the performance counter. It''s an OpenGL tutorial but if you just look for the timer functions, you will find what you want.

##### Share on other sites
QueryPerformanceCounter() gives you the number of "clock ticks" that have occurred since the system was turned on.

QueryPerformanceFrequency() gives you how many of these "clock ticks" there are in one second.

By taking the value of the counter and dividing by the frequency, you get the number of seconds that have elapsed since the system was turned on.

The values you get from these functions are 64-bit integers - check out the LARGE_INTEGER entry in MSDN for details.

[edited by - MisterMoot on July 28, 2003 2:25:28 AM]

##### Share on other sites
Use QueryPerformanceFrequency to get the frequency of the high-resolution timer (ie. the number of ticks per second).

Then use QueryPerformanceCounter to get the current tick count.

Then simply take the difference between the tick counts and divide by the frequency:

LARGE_INTEGER freq = QueryPerformanceFrequency();
LARGE_INTEGER time1 = QueryPerformanceCounter();

...
...

LARGE_INTEGER time2 = QueryPerformanceCounter();

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633665
• Total Posts
3013245
×