[Python-Dev] Use QueryPerformanceCounter() for time.monotonic() and/or time.highres()?

Victor Stinner victor.stinner at gmail.com
Fri Mar 30 22:21:28 CEST 2012


Hi,

Windows provides two main monotonic clocks: QueryPerformanceCounter()
and GetTickCount(). QueryPerformanceCounter() has a good accuracy (0.3
ns - 5 ns) but has various issues and is know to not have a steady
rate. GetTickCount() has a worse accuracy (1 ms - 15 ms) but is more
stable and behave better on system suspend/resume.

The glib library prefers GetTickCount() over QueryPerformanceCounter()
for its g_get_monotonic_time() because "The QPC timer has too many
issues to be used as is."
Ihttp://mail.gnome.org/archives/commits-list/2011-November/msg04589.html

The Qt library tries QueryPerformanceCounter() but may fallback to
GetTickCount() if it is not available.

python-monotonic-time only uses GetTickCount() or GetTickCount64().

It is important to decide which clock is used for the Python
time.monotonic() because it may change the design of the PEP 418. If
we use GetTickCount() for time.monotonic(), we should use
QueryPerformanceCounter() for time.highres(). But in this case, it
means that time.highres() is not a simple "try monotonic or falls back
to system time", but may use a different clock with an higher
resolution. So we might add a third function for the "try monotonic or
falls back to system time" requirement.

Python implements time.clock() using QueryPerformanceCounter() on Windows.

Victor


More information about the Python-Dev mailing list