Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does GetTickCount() actually measure?

Tags:

winapi

I want to know what does the Windows API GetTickCount() actually measure? Does it measure the time from the instant the power button of the system is pressed? Does it measure the time taken by bootloaders or BIOS to load as well? I am trying to measure the boot time on Windows 7.

like image 225
user1931217 Avatar asked Mar 19 '13 15:03

user1931217


People also ask

What does GetTickCount return?

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

How accurate is GetTickCount?

The GetTickCount function has a precision of one millisecond, but its accuracy is typically much worse, dependent on your timer tick rate, typically 10ms to 55ms.


2 Answers

You should not treat it as measuring the time "since" anything. Use it only as a relative clock source. In other words, call GetTickCount once, then do something, then call it again, then subtract. Do not use the absolute value of the tick count.

The precise start time is unspecified, and on debugging builds of Windows, the "boot time" is artificially set to 49.7 days in the past in order to expose timer rollover bugs.

like image 187
Raymond Chen Avatar answered Oct 23 '22 01:10

Raymond Chen


Since the official documentation doesn't specify, you can only assume that the precise moment during startup is not really defined, and it could work differently on different versions of Windows. But consider that with virtualization and emulation, "since the power button was pushed" would be meaningless. The best consistent definition you could hope for would be the moment that Windows starts serving interrupts -- the earliest moment that the system clock is available.

like image 26
Ernest Friedman-Hill Avatar answered Oct 23 '22 02:10

Ernest Friedman-Hill