Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetTickCount function

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

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

var1 and var2 has same values in it.

can someone help?

like image 846
Leonid Avatar asked Aug 10 '10 20:08

Leonid


People also ask

What does GetTickCount return?

The return value is the number of milliseconds that have elapsed since the system was started.

What is tick count in Windows?

GetTickCount function (sysinfoapi. h) - Win32 apps. Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.


3 Answers

Assuming this is the Windows GetTickCount call, that's entirely reasonable:

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

Note that it's only measuring milliseconds to start with - and you can do an awful lot in a millisecond these days.

The docs go on to say:

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

Perhaps QueryPerformanceCounter would be more appropriate?

like image 182
Jon Skeet Avatar answered Oct 26 '22 08:10

Jon Skeet


If you go the QueryPerformanceCounter route you need to watch out for hardware dependent wierdness. Its been awhile so I don't know if this kinda stuff still happens.

You might also want to take a look at this link since it has a nice sample app which compares QueryPerformanceCounter, GetTickCount and TimeGetTime

like image 40
Conrad Frix Avatar answered Oct 26 '22 07:10

Conrad Frix


If you are referring to the Windows API call then read this. I would guess that you are trying to time a short interval so this paragraph is relevant. Are you timing something shorter than that interval? If so look into QueryPerformanceCounter instead perhaps.

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

like image 34
jcoder Avatar answered Oct 26 '22 06:10

jcoder