PEP 418: Remove duplicate info about clock resolution

This commit is contained in:
Victor Stinner 2012-04-13 02:16:55 +02:00
parent 03cd4d6a64
commit 61b5e2476c
1 changed files with 19 additions and 53 deletions

View File

@ -264,23 +264,19 @@ Pseudo-code [#pseudo]_::
def time(): def time():
if hasattr(time, "clock_gettime"): if hasattr(time, "clock_gettime"):
try: try:
# resolution = 1 nanosecond
return time.clock_gettime(time.CLOCK_REALTIME) return time.clock_gettime(time.CLOCK_REALTIME)
except OSError: except OSError:
# CLOCK_REALTIME is not supported (unlikely) # CLOCK_REALTIME is not supported (unlikely)
pass pass
if hasattr(_time, "gettimeofday"): if hasattr(_time, "gettimeofday"):
try: try:
# resolution = 1 microsecond
return _time.gettimeofday() return _time.gettimeofday()
except OSError: except OSError:
# gettimeofday() should not fail # gettimeofday() should not fail
pass pass
if hasattr(_time, "ftime"): if hasattr(_time, "ftime"):
# resolution = 1 millisecond
return _time.ftime() return _time.ftime()
else: else:
# resolution = 1 second
return _time.time() return _time.time()
@ -722,9 +718,9 @@ CLOCK_MONOTONIC OpenBSD 5.0 10 ms
GetTickCount Windows Seven 15.6 ms GetTickCount Windows Seven 15.6 ms
========================= ================ =============== ========================= ================ ===============
For CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW, the precision of this For CLOCK_xxx clocks, the precision of this table is the result of
table is the result of ``clock_getres()``. It looks like Linux does ``clock_getres()``. It looks like Linux does not implement ``clock_getres()``
not implement ``clock_getres()`` and always returns 1 nanosecond. and always returns 1 nanosecond.
mach_absolute_time mach_absolute_time
^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
@ -743,8 +739,6 @@ mach_absolute_time() stops during a sleep on a PowerPC CPU, but not on
an Intel CPU: `Different behaviour of mach_absolute_time() on i386/ppc an Intel CPU: `Different behaviour of mach_absolute_time() on i386/ppc
<http://lists.apple.com/archives/PerfOptimization-dev/2006/Jul/msg00024.html>`_. <http://lists.apple.com/archives/PerfOptimization-dev/2006/Jul/msg00024.html>`_.
mach_absolute_time() has a resolution of 1 nanosecond.
CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_BOOTTIME CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_BOOTTIME
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -792,9 +786,6 @@ CLOCK_MONOTONIC stops while the machine is suspended.
clock, even if the standard C library supports it. For example, clock, even if the standard C library supports it. For example,
CLOCK_MONOTONIC_RAW requires a kernel version 2.6.28 or later. CLOCK_MONOTONIC_RAW requires a kernel version 2.6.28 or later.
``clock_getres()`` gives the clock resolution. It is 1 nanosecond on
Linux.
.. note:: .. note::
``clock_gettime()`` requires to link the program against the rt ``clock_gettime()`` requires to link the program against the rt
@ -881,15 +872,14 @@ includes time the system spends in sleep or hibernation.
GetTickCount64() was added to Windows Vista and Windows Server 2008. GetTickCount64() was added to Windows Vista and Windows Server 2008.
The clock resolution is 1 millisecond. Its precision is usually It is possible to improve the precision using the `undocumented
around 15 ms. It is possible to improve the precision using the NtSetTimerResolution() function
`undocumented NtSetTimerResolution() function
<http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Time/NtSetTimerResolution.html>`_. <http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Time/NtSetTimerResolution.html>`_.
There are applications using this undocumented function, example: There are applications using this undocumented function, example: `Timer
`Timer Resolution <http://www.lucashale.com/timer-resolution/>`_. Resolution <http://www.lucashale.com/timer-resolution/>`_.
WaitForSingleObject() uses the same timer as GetTickCount() with the WaitForSingleObject() uses the same timer as GetTickCount() with the
same resolution. same precision.
GetTickCount() has an precision of 55 ms on Windows 9x. GetTickCount() has an precision of 55 ms on Windows 9x.
@ -990,16 +980,9 @@ and always returns 1 nanosecond.
Windows: GetSystemTimeAsFileTime Windows: GetSystemTimeAsFileTime
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The system time can be read using GetSystemTimeAsFileTime(), ftime() The system time can be read using GetSystemTimeAsFileTime(), ftime() and
and time(). time(). The precision of the system clock can be read using
GetSystemTimeAdjustment().
The system time resolution can be read using
GetSystemTimeAdjustment(). The precision is usually between 1
millisecond and 15 milliseconds. Resolution:
* GetSystemTimeAsFileTime(): 100 nanoseconds
* ftime(): 1 millisecond
* time(): 1 second
Read the `GetSystemTimeAsFileTime() documentation Read the `GetSystemTimeAsFileTime() documentation
<http://msdn.microsoft.com/en-us/library/windows/desktop/ms724397(v=vs.85).aspx>`_. <http://msdn.microsoft.com/en-us/library/windows/desktop/ms724397(v=vs.85).aspx>`_.
@ -1012,13 +995,6 @@ System time on UNIX
gettimeofday(), ftime(), time() and clock_gettime(CLOCK_REALTIME) gettimeofday(), ftime(), time() and clock_gettime(CLOCK_REALTIME)
return the system clock. return the system clock.
Resolution:
* clock_gettime(): clock_getres(CLOCK_REALTIME)
* gettimeofday(): 1 microsecond
* ftime(): 1 millisecond
* time(): 1 second
The system time can be set using settimeofday() or The system time can be set using settimeofday() or
clock_settime(CLOCK_REALTIME). clock_settime(CLOCK_REALTIME).
@ -1071,7 +1047,8 @@ GetSystemTimeAdjustment().
Functions Functions
^^^^^^^^^ ^^^^^^^^^
* Windows: GetProcessTimes() * Windows: GetProcessTimes(). The precision can be read using
GetSystemTimeAdjustment().
* clock_gettime(CLOCK_PROCESS_CPUTIME_ID): High-resolution per-process * clock_gettime(CLOCK_PROCESS_CPUTIME_ID): High-resolution per-process
timer from the CPU. timer from the CPU.
* clock(): * clock():
@ -1085,13 +1062,6 @@ Functions
* times() * times()
* getrusage(): ru_utime and ru_stime fields * getrusage(): ru_utime and ru_stime fields
Resolution:
* clock() rate is CLOCKS_PER_SEC. It was called CLK_TCK in Microsoft
C before 6.0.
* The clock resolution can be read using clock_getres().
* GetProcessTimes(): call GetSystemTimeAdjustment().
Python source code includes a portable library to get the process time (CPU Python source code includes a portable library to get the process time (CPU
time): `Tools/pybench/systimes.py time): `Tools/pybench/systimes.py
<http://hg.python.org/cpython/file/tip/Tools/pybench/systimes.py>`_. <http://hg.python.org/cpython/file/tip/Tools/pybench/systimes.py>`_.
@ -1128,15 +1098,11 @@ the precision is read using GetSystemTimeAdjustment().
Functions Functions
^^^^^^^^^ ^^^^^^^^^
* Windows: GetThreadTimes() * Windows: GetThreadTimes(). The precision can be read using
GetSystemTimeAdjustment().
* clock_gettime(CLOCK_THREAD_CPUTIME_ID): Thread-specific CPU-time * clock_gettime(CLOCK_THREAD_CPUTIME_ID): Thread-specific CPU-time
clock. clock.
Resolution:
* CLOCK_THREAD_CPUTIME_ID: call clock_getres().
* GetThreadTimes(): call GetSystemTimeAdjustment()
See also pthread_getcpuclockid(). See also pthread_getcpuclockid().
@ -1273,10 +1239,10 @@ Other functions
* sem_timedwait(): "If the Timers option is supported, the timeout * sem_timedwait(): "If the Timers option is supported, the timeout
shall be based on the CLOCK_REALTIME clock. If the Timers option is shall be based on the CLOCK_REALTIME clock. If the Timers option is
not supported, the timeout shall be based on the system clock as not supported, the timeout shall be based on the system clock as
returned by the time() function. The resolution of the timeout returned by the time() function. The precision of the timeout
shall be the resolution of the clock on which it is based." shall be the precision of the clock on which it is based."
* WaitForSingleObject(): use the same timer than GetTickCount() with * WaitForSingleObject(): use the same timer than GetTickCount() with
the same resolution. the same precision.
Alternatives: API design Alternatives: API design
@ -1336,7 +1302,7 @@ One function choosing the clock from a list of constraints
* time.MONOTONIC: clock cannot go backward * time.MONOTONIC: clock cannot go backward
* time.STEADY: clock rate is steady and the clock is not adjusted * time.STEADY: clock rate is steady and the clock is not adjusted
* time.HIGHRES: clock with the highest resolutions * time.HIGHRES: clock with the highest precision
time.get_clock() returns None if the clock is found and so calls can time.get_clock() returns None if the clock is found and so calls can
be chained using the or operator. Example:: be chained using the or operator. Example::