PDA

View Full Version : GetTickCount



Crisp_N_Dry
28-03-2005, 06:15 PM
I'm using GetTickCount as a controller for a game framework I'm building. I've setup a logging mechanism for the entire framework so that I can easily track what's going on inside my program and analyse it at my leisure. While working on the timer for the game I've decided to output the results of GetTickCount to my log file and see exactly how fast the code is running. So I did just that but when I analysed my data I noticed something odd. The log tickcount only changes every 3500 entries and when it does it suddenly jumps by about 16 milliseconds. So instead of a smooth flow from 1 millisecond to the next it jumps by 16 milliseconds. I know it's not because of slow code because it logs about 3500 logs all with the same TickCount before it jumps. It would seem that GetTickCount isn't very accurate and is only changing once every 0.016 of a second. Can anyone confirm this?

siim
28-03-2005, 06:27 PM
The accuracy of GetTickCount depends on how often windows updates system timer. The resolution can be as low as 50ms.

Use QueryPerformanceCounter/QueryPerformanceFrequency for accurate timing.

Clootie
28-03-2005, 06:30 PM
Yes, this is how it works. You can enhance it by using timeBeginPeriod(1); time:= timeGetTime; timeEndPeriod(1); to around 1ms range.

But it's better to use QueryPerformanceFrequency / QueryPerformanceCounter functions.

Clootie
28-03-2005, 06:33 PM
:D