Gettickcount function

I have a question regarding the GetTickCount function. I have two calls to this function in my code with several commands between them, and the function returns the same score in both calls. i.e.

var1 = GetTickCount(); code : : var2 = GetTickCount(); 

var1 and var2 have the same values ​​in it.

can anyone help?

+6
c time gettickcount
source share
6 answers

Suppose this is a Windows call to GetTickCount , which is perfectly reasonable:

The resolution of the GetTickCount function is limited by the resolution of the system timer, which is usually in the range of 10 milliseconds to 16 milliseconds.

Note that these are just milliseconds to begin with - and you can do a lot in milliseconds these days.

The docs say:

If you need a timer with a higher resolution, use a multimedia timer or a timer with a higher resolution .

Perhaps a QueryPerformanceCounter would be more appropriate?

+14
source share

If you are accessing a Windows API call, read this . I would suggest that you try to make a short period of time, so this paragraph matters. Do you think something is shorter than this interval? If possible, take a look at the QueryPerformanceCounter.

The resolution of the GetTickCount function is limited by the resolution of the system timer, which is usually in the range of 10 milliseconds to 16 milliseconds. GetTickCount permission on a function is not affected by adjustments made by the GetSystemTimeAdjustment function.

+5
source share

If you are following the QueryPerformanceCounter route, you need to keep an eye on the hardware-dependent wierdness . It has been a while, so I don’t know what is still happening.

You can also take a look at this link , as it has a good sample application that compares QueryPerformanceCounter, GetTickCount and TimeGetTime

+5
source share

From MSDN

The resolution of the GetTickCount function is limited by the resolution of the system timer, which is usually in the range of 10 milliseconds to 16 milliseconds. GetTickCount permission on a function is not affected by adjustments made by the GetSystemTimeAdjustment function.

Elapsed time is stored as DWORD value. Therefore, the time will be completed around zero if the system is running continuously for 49.7 days. To avoid this problem, use the GetTickCount64 function. Otherwise, check for overflows when comparing times.

If you need a timer with a higher resolution, use a multimedia timer or a timer with a higher resolution.

+2
source share

GetTickCount has a resolution of one millisecond (in practice, it is a few milliseconds). It is very likely that the functions you call between them take significantly less than 1 millisecond.

+1
source share
 dwStartTimer=GetTickCount(); dwEndTimer=GetTickCount(); while((dwEndTimer-dwStartTimer)<wDelay)//5000 milli seconds delay { Sleep(200); dwEndTimer=GetTickCount(); if (PeekMessage (&uMsg, NULL, 0, 0, PM_REMOVE) > 0) //Or use an if statement { TranslateMessage (&uMsg); DispatchMessage (&uMsg); } } 
0
source share

All Articles