[Python-Dev] time.clock() on windows

Curt Hagenlocher curt at hagenlocher.org
Wed Oct 21 23:31:13 CEST 2009

On Wed, Oct 21, 2009 at 1:51 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Kristján Valur Jónsson <kristjan <at> ccpgames.com> writes:
>> You are right, on windows time.clock() is based relative to its first call
>> in the process.  There is no such promise made on unix.
>> QueryPerformanceCounter() (what time.clock uses()) is a robust high
>> resolution timer that is processor/core independent.  It should be
>> possible to use it across different processes too, if this
>> annoying rebasing wasn't there.
> Well, could we simply have a high-resolution time.time()?
> Or is Windows just too limited to provide this?

Presumably you could fake something like this by combining output from
an initial time(), an initial QueryPerformanceCounter() and the
current QueryPerformanceCounter(). But it makes more sense to
understand why someone chose to implement time.clock() on Windows the
way they did -- this seems very broken to me, and I think it should be

Of course, there are no doubt people relying on the broken behavior...

Curt Hagenlocher
curt at hagenlocher.org

More information about the Python-Dev mailing list