[Python-Dev] time.clock() on windows
Kristján Valur Jónsson
kristjan at ccpgames.com
Thu Oct 22 15:39:21 CEST 2009
> -----Original Message-----
> From: Mark Hammond [mailto:mhammond at skippinet.com.au]
> Sent: 22. október 2009 10:58
> To: Kristján Valur Jónsson
> Cc: Scott Dial; python-dev at python.org
> It was made in the context of the APIs available to implement this.
> The
> code is short-and-sweet in timemodule.c, so please do go ahead and fix
> my flawed reasoning.
...
I'm sorry, I don't want to start a flame war here, it just seems that if you need a zero point, and arbitrarily choose the first call to time.clock(), you could just as well use the implicit zero point already provided by the system.
> -----Original Message-----
> From: python-dev-bounces+kristjan=ccpgames.com at python.org
> [mailto:python-dev-bounces+kristjan=ccpgames.com at python.org] On Behalf
> Of M.-A. Lemburg
> I'm not sure I understand why time.clock() should be considered
> broken.
Ah, well, not broken, but it could be even more useful: If it used the implicit system-wide epoch rather than the one based on the first call within each process, it could be useful for cross-process high-resolution timings.
Anyway, it is simple enough to patch it on windows using ctypes if one needs that kind of behaviour:
#nuclock.py
import ctypes
import time
counter = ctypes.c_uint64()
pcounter = ctypes.byref(counter)
ctypes.windll.kernel32.QueryPerformanceFrequency(pcounter)
frequency = float(counter.value)
QPC = ctypes.windll.kernel32.QueryPerformanceCounter
def nuclock():
QPC(pcounter)
return float(counter.value)/frequency
time.clock = nuclock
Cheers,
Kristjan
More information about the Python-Dev
mailing list