views:

798

answers:

3

This article on microsoft's tech net site supplies an exe that will calculate your windows machine's minimum time resolution - this should be the smallest "tick" available to any application on that machine:

[http://technet.microsoft.com/en-us/sysinternals/bb897568.aspx][1]

The result of running this app on my current box is 15.625 ms. I have also run tests against Internet Explorer and gotten the exact same resolution from the Date() javascript function.

What is confusing is that the SAME test I ran against IE gives back much finer resolution for Google's Chrome browser (resolution of 1ms) and for a flash movie running in IE (1ms). Can anyone explain how any application can get a clock resolution better then the machine's clock? If so, is there some way I can get a consistantly better resolution in browsers other then Chrome (without using flash)?

The first answer below leads to two other questions:

  1. How does a multi-media timer get times between system clock ticks. I imagine the system clock as an analog watch with a ticking hand, each tick being 15ms. How are times between ticks measured?
  2. Are multimedia timers available to browsers, especially Internet Explorer? Can I access one with C# or Javascipt without having to push software to a user's browser/machine?
+4  A: 

You can get down to 1 ms with multimedia timers and even further with QueryPerformanceCounter.

See also GetLocalTime() API time resolution.

EDIT: Partial answer to the new subquestion ...

System time resolution was around 15 ms on the Windows 3 and 95 architecture. On NT (and successors) you can get better resolution from the hardware abstraction layer (HAL). The QueryPerformanceCounter counts elapsed time, not CPU cycles article, written by the Raymond Chen, may give you some additional insights.

As for the browsers - I have no idea what they are using for timers and how they interact with the OS.

gabr
Interesting. This leads to to additional queestions:
WillR
Unfortunately pre-vista the setting is global (eg. all timers in the system become higher res which can cause problems); It also does really bad things to power usage (although i don't know to what extent that is OS dependent)
olliej
A: 

The APIC on the processor runs at bus speed and has a timer. They may be using that instead of the system time. (Or they might just be giving a bunch of precision that isn't there.)

This description of the Local APIC mentions using it as a timer.

(It may also be the case that there is some performance counter they are using. That actually seems more likely since a device driver would be needed to program the APIC.)

Steve Steiner
+1  A: 

Look at the timeBeginPeriod API. From MSDN: "This function affects a global Windows setting. Windows uses the lowest value (that is, highest resolution) requested by any process."

http://msdn.microsoft.com/en-us/library/ms713413(VS.85).aspx

(Markdown didn't like parens in the URL)

See "Inside Windows NT High Resolution Timers" referenced from the link you posted.

Harold Ekstrom
In URLs, you can safely replace the opening parens with %28 and the closing one with %29. This works around the markdown annoyance.
Mihai Limbășan