Message143205
I think that we should process in two steps:
* Expose low level C functions
* Write a high level reusing the best low level function depending on the OS
Low level functions:
* Expose clock_gettime() into the time module, with CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW constants, if available. The wrapper should be thin, so the result would be a tuple (sec, nsec) (to avoid issues with floating point numbers)
* Windows: GetTickCount, GetTickCount64 and QueryPerformaceCounter are monotonic. GetTickCount wraps after 50 days, so GetTickCount64 should be preferred. GetTickCount(64) returns a number of milliseconds. It looks like QueryPerformaceCounter has a better resolution than GetTickCount(64). I don't know when QueryPerformaceCounter does wrap? QueryPerformaceCounter is already exposed as time.clock().
High level:
* Use clock_gettime(CLOCK_MONOTONIC_RAW) on Linux>=2.6.28
* Use clock_gettime(CLOCK_MONOTONIC) on UNIX
* Use time.clock() (QueryPerformaceCounter) on Windows?
* If none of these functions is available, don't define the function
I propose time.monotonic() because I saw this name in different projects.
Pseudo-code for the time module:
monotonic = None
if hasattr(time, 'clock_gettime'):
if hasattr(time, 'CLOCK_MONOTONIC_RAW'):
def monotonic(): return time.clock_gettime(CLOCK_MONOTONIC_RAW)
else:
# i don't think that we should expose clock_gettime
# if CLOCK_MONOTONIC is not available (or the function is useless)
def monotonic(): return time.clock_gettime(CLOCK_MONOTONIC)
elif os.name == 'nt':
def monotonic(): return time.clock()
if monotonic is not None:
monotonic.__doc__ = 'monotonic time'
else:
del monotonic |
|
Date |
User |
Action |
Args |
2011-08-30 09:11:37 | vstinner | set | recipients:
+ vstinner, belopolsky, pitrou, kristjan.jonsson, eric.araujo, michael.foord, brian.curtin, glenn, anacrolix |
2011-08-30 09:11:37 | vstinner | set | messageid: <1314695497.71.0.402844870684.issue10278@psf.upfronthosting.co.za> |
2011-08-30 09:11:37 | vstinner | link | issue10278 messages |
2011-08-30 09:11:36 | vstinner | create | |
|