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():
if hasattr(time, "clock_gettime"):
try:
# resolution = 1 nanosecond
return time.clock_gettime(time.CLOCK_REALTIME)
except OSError:
# CLOCK_REALTIME is not supported (unlikely)
pass
if hasattr(_time, "gettimeofday"):
try:
# resolution = 1 microsecond
return _time.gettimeofday()
except OSError:
# gettimeofday() should not fail
pass
if hasattr(_time, "ftime"):
# resolution = 1 millisecond
return _time.ftime()
else:
# resolution = 1 second
return _time.time()
@ -722,9 +718,9 @@ CLOCK_MONOTONIC OpenBSD 5.0 10 ms
GetTickCount Windows Seven 15.6 ms
========================= ================ ===============
For CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW, the precision of this
table is the result of ``clock_getres()``. It looks like Linux does
not implement ``clock_getres()`` and always returns 1 nanosecond.
For CLOCK_xxx clocks, the precision of this table is the result of
``clock_getres()``. It looks like Linux does not implement ``clock_getres()``
and always returns 1 nanosecond.
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
<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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -792,9 +786,6 @@ CLOCK_MONOTONIC stops while the machine is suspended.
clock, even if the standard C library supports it. For example,
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::
``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.
The clock resolution is 1 millisecond. Its precision is usually
around 15 ms. It is possible to improve the precision using the
`undocumented NtSetTimerResolution() function
It is possible to improve the precision using the `undocumented
NtSetTimerResolution() function
<http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Time/NtSetTimerResolution.html>`_.
There are applications using this undocumented function, example:
`Timer Resolution <http://www.lucashale.com/timer-resolution/>`_.
There are applications using this undocumented function, example: `Timer
Resolution <http://www.lucashale.com/timer-resolution/>`_.
WaitForSingleObject() uses the same timer as GetTickCount() with the
same resolution.
same precision.
GetTickCount() has an precision of 55 ms on Windows 9x.
@ -990,16 +980,9 @@ and always returns 1 nanosecond.
Windows: GetSystemTimeAsFileTime
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The system time can be read using GetSystemTimeAsFileTime(), ftime()
and time().
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
The system time can be read using GetSystemTimeAsFileTime(), ftime() and
time(). The precision of the system clock can be read using
GetSystemTimeAdjustment().
Read the `GetSystemTimeAsFileTime() documentation
<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)
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
clock_settime(CLOCK_REALTIME).
@ -1071,7 +1047,8 @@ GetSystemTimeAdjustment().
Functions
^^^^^^^^^
* Windows: GetProcessTimes()
* Windows: GetProcessTimes(). The precision can be read using
GetSystemTimeAdjustment().
* clock_gettime(CLOCK_PROCESS_CPUTIME_ID): High-resolution per-process
timer from the CPU.
* clock():
@ -1085,13 +1062,6 @@ Functions
* times()
* 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
time): `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
^^^^^^^^^
* Windows: GetThreadTimes()
* Windows: GetThreadTimes(). The precision can be read using
GetSystemTimeAdjustment().
* clock_gettime(CLOCK_THREAD_CPUTIME_ID): Thread-specific CPU-time
clock.
Resolution:
* CLOCK_THREAD_CPUTIME_ID: call clock_getres().
* GetThreadTimes(): call GetSystemTimeAdjustment()
See also pthread_getcpuclockid().
@ -1273,10 +1239,10 @@ Other functions
* sem_timedwait(): "If the Timers option is supported, the timeout
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
returned by the time() function. The resolution of the timeout
shall be the resolution of the clock on which it is based."
returned by the time() function. The precision of the timeout
shall be the precision of the clock on which it is based."
* WaitForSingleObject(): use the same timer than GetTickCount() with
the same resolution.
the same precision.
Alternatives: API design
@ -1336,7 +1302,7 @@ One function choosing the clock from a list of constraints
* time.MONOTONIC: clock cannot go backward
* 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
be chained using the or operator. Example::