yes i am thinking this is not correct function call for what you want to achieve.mar wrote:It depends on system you use, though i doubt you get 1ms granularity with GetTickCount().diep wrote:Let me write it again. It has granularity internal of within a nanosecond that gets converted. So if it says something has been eating 3 milliseconds, it can be 3.000 or 3.999 but not 4 milliseconds and definitely not 2.1 milliseconds.
Here's what I get on XP using GetTickCount():
delta = 0 ms
delta = 16 ms
delta = 31 ms
delta = 47 ms
delta = 63 ms
...
and using timeGetTime():
delta = 0 ms
delta = 1 ms
delta = 2 ms
delta = 3 ms
delta = 4 ms
...
With other words, anything that takes less that 16 msec, measured using GetTickCount, will report either 0ms or 16ms.
You are measuring wrong thing probably. You are measuring runqueue latency. It fires in theory at 100Hz. So minimum delay 10 milliseconds. In reality with 2 cpu's here it's a lot slower that kernel of course. We see that if we do a sleep(0) it's soon 31-47 milliseconds. Not 10 milliseconds at all

Kernel obviously at 16 ms granularity as you call it. It's just antique shjt.
However we get total zero latency from the timer itself of course. Just don't flood it. Kernel might idle you or push it away or whatever i don't know. XP is still supported by microsoft by the way?
But to say it very correct. Each time kernel wakes up and checks runqueue it is updating the register of GetTickCount(), do i say it ok like this?
So call is very cheap. timing is very accurate, just not the microseconds level you want it to be. So you sure need other functioncall for what you want

If you do 2 measurements short after each other without flooding the kernel you get real timing see here 0 seconds latency between each call:
Code: Select all
#include <windows.h>
#include <stdio.h>
int main(void) {
unsigned int Tstart = (unsigned int)GetTickCount(),Tprev=Tstart;
int i = 0;
while( i < 50 ) {
unsigned int t1,t2,delta,absdelta;
t1 = (unsigned int)GetTickCount();
t2 = (unsigned int)GetTickCount();
delta = t2-t1;
absdelta = t1-Tstart;
printf("t2-t1 = %u absolute time +%u = %u\n",
t2-t1,t1-Tprev,absdelta);
Sleep(0); // now we sleep for a while to not flood kernel
// with requests or it might idle us for a while
i++;
Tprev = t1;
}
return 0;
}
C:\test>ticktock
t2-t1 = 0 absolute time +0 = 0
t2-t1 = 0 absolute time +46 = 46
t2-t1 = 0 absolute time +32 = 78
t2-t1 = 0 absolute time +46 = 124
t2-t1 = 0 absolute time +32 = 156
t2-t1 = 0 absolute time +46 = 202
t2-t1 = 0 absolute time +32 = 234
t2-t1 = 0 absolute time +46 = 280
t2-t1 = 0 absolute time +32 = 312
t2-t1 = 0 absolute time +31 = 343
t2-t1 = 0 absolute time +47 = 390
t2-t1 = 0 absolute time +31 = 421
t2-t1 = 0 absolute time +31 = 452
t2-t1 = 0 absolute time +47 = 499
t2-t1 = 0 absolute time +31 = 530
t2-t1 = 0 absolute time +31 = 561
t2-t1 = 0 absolute time +47 = 608
t2-t1 = 0 absolute time +31 = 639
t2-t1 = 0 absolute time +31 = 670
t2-t1 = 0 absolute time +47 = 717
t2-t1 = 0 absolute time +31 = 748
t2-t1 = 0 absolute time +32 = 780
t2-t1 = 0 absolute time +46 = 826
t2-t1 = 0 absolute time +32 = 858
t2-t1 = 0 absolute time +31 = 889
t2-t1 = 0 absolute time +47 = 936
t2-t1 = 0 absolute time +31 = 967
t2-t1 = 0 absolute time +31 = 998
t2-t1 = 0 absolute time +47 = 1045
t2-t1 = 0 absolute time +31 = 1076
t2-t1 = 0 absolute time +31 = 1107
t2-t1 = 0 absolute time +47 = 1154
t2-t1 = 0 absolute time +31 = 1185
t2-t1 = 0 absolute time +31 = 1216
t2-t1 = 0 absolute time +32 = 1248
t2-t1 = 0 absolute time +46 = 1294
t2-t1 = 0 absolute time +32 = 1326
t2-t1 = 0 absolute time +31 = 1357
t2-t1 = 0 absolute time +47 = 1404
t2-t1 = 0 absolute time +31 = 1435
t2-t1 = 0 absolute time +31 = 1466
t2-t1 = 0 absolute time +47 = 1513
t2-t1 = 0 absolute time +31 = 1544
t2-t1 = 0 absolute time +31 = 1575
t2-t1 = 0 absolute time +47 = 1622
t2-t1 = 0 absolute time +31 = 1653
t2-t1 = 0 absolute time +31 = 1684
t2-t1 = 0 absolute time +47 = 1731
t2-t1 = 0 absolute time +31 = 1762
t2-t1 = 0 absolute time +32 = 1794
*/