Message146357
| Author |
vstinner |
| Recipients |
anacrolix, belopolsky, brian.curtin, eric.araujo, glenn, kristjan.jonsson, michael.foord, pitrou, python-dev, vstinner |
| Date |
2011年10月25日.11:28:21 |
| SpamBayes Score |
1.3746781e-12 |
| Marked as misclassified |
No |
| Message-id |
<1319542102.4.0.630134203876.issue10278@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
I closed maybe this issue too quickly. My commit doesn't solve the initial issue: Python doesn't provide a portable "wallclock" function.
wallclock.patch should be updated to use:
- time.clock() on Windows (use QueryPerformanceCounter)
- or time.clock_gettime(CLOCK_MONOTONIC_RAW) if available
- or time.clock_gettime(CLOCK_MONOTONIC) if available
- or time.time() (which is usually gettimeofday())
Pseudo-code:
wallclock = None
if hasattr(time, 'clock_gettime') and hasattr(time, 'CLOCK_MONOTONIC_RAW'):
# I understood that CLOCK_MONOTONIC_RAW is more reliable
# than CLOCK_MONOTONIC, because CLOCK_MONOTONIC may be adjusted
# by NTP. I don't know if it's correct.
def wallclock():
return time.clock_gettime(CLOCK_MONOTONIC_RAW)
elif hasattr(time, 'clock_gettime') and hasattr(time, 'CLOCK_MONOTONIC'):
def wallclock():
return time.clock_gettime(CLOCK_MONOTONIC)
elif os.name == 'nt':
# define a new function to be able to set its docstring
def wallclock():
return time.clock()
else:
def wallclock():
return time.time()
if wallclock is not None:
wallclock.__doc__ = 'monotonic time'
else:
del wallclock
wallclock() doc should also explain that time.time() may be adjusted by NTP or manually by the administrator.
--
By the way, it would be nice to expose the precision of time.clock(): it's 1/divisor or 1/CLOCKS_PER_SEC on Windows, 1/CLOCKS_PER_SEC on UNIX. |
|