PEP 418: Cleanup info on precision

This commit is contained in:
Victor Stinner 2012-04-14 00:47:00 +02:00
parent 44f95fb601
commit f0c1353bde
2 changed files with 30 additions and 41 deletions

View File

@ -708,9 +708,10 @@ Monotonic clocks
========================= ========== =============== ============= ===============
Name Resolution Adjusted Include sleep Include suspend
========================= ========== =============== ============= ===============
gethrtime 1 ns No Yes Yes
gethrtime() 1 ns No Yes Yes
CLOCK_HIGHRES 1 ns No Yes ?
CLOCK_MONOTONIC 1 ns Slewed on Linux Yes No
CLOCK_MONOTONIC_COARSE 1 ns Slewed on Linux Yes No
CLOCK_MONOTONIC_RAW 1 ns No Yes No
CLOCK_BOOTTIME 1 ns ? Yes Yes
CLOCK_UPTIME 1 ns No Yes ?
@ -733,13 +734,10 @@ CLOCK_MONOTONIC FreeBSD 8.2 11 ns 7 µs
CLOCK_MONOTONIC OpenBSD 5.0 10 ms 7 µs
QueryPerformanceCounter Windows Seven 10 ns 9 µs
CLOCK_UPTIME FreeBSD 8.2 11 ns 9 µs
CLOCK_MONOTONIC_COARSE Linux 3.3 1 ms 1 ms
GetTickCount Windows Seven 16 ms 15 ms
========================= ================ ========= ===================
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
^^^^^^^^^^^^^^^^^^
@ -761,7 +759,8 @@ CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_BOOTTIME
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW represent monotonic time since
some unspecified starting point. They cannot be set.
some unspecified starting point. They cannot be set. The precision
can be read using ``clock_getres()``.
Documentation: refer to the manual page of your operating system.
Examples:
@ -800,6 +799,9 @@ suspend <http://lwn.net/Articles/429925/>`_ (March, 2011).
CLOCK_MONOTONIC stops while the machine is suspended.
Linux provides also CLOCK_MONOTONIC_COARSE since Linux 2.6.32. It is
similar to CLOCK_MONOTONIC, less precise but faster.
``clock_gettime()`` fails if the system does not support the specified
clock, even if the standard C library supports it. For example,
CLOCK_MONOTONIC_RAW requires a kernel version 2.6.28 or later.
@ -809,16 +811,12 @@ CLOCK_MONOTONIC_RAW requires a kernel version 2.6.28 or later.
``clock_gettime()`` requires to link the program against the rt
(real-time) library.
.. note::
Linux provides also CLOCK_MONOTONIC_COARSE since Linux 2.6.32 which
has less accuracy than CLOCK_MONOTONIC but is faster.
Windows: QueryPerformanceCounter
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
High-resolution performance counter. It is monotonic.
QueryPerformanceFrequency() gives its frequency.
The frequency of the counter can be read using QueryPerformanceFrequency().
The precision is 1 / QueryPerformanceFrequency().
It has a much higher resolution, but has lower long term precision
than GetTickCount() and timeGetTime() clocks. For example, it will
@ -884,6 +882,7 @@ not adjusted by SetSystemTimeAdjustment(). MSDN documentation:
<http://msdn.microsoft.com/en-us/library/windows/desktop/ms724408(v=vs.85).aspx>`_,
`GetTickCount64()
<http://msdn.microsoft.com/en-us/library/windows/desktop/ms724411(v=vs.85).aspx>`_.
The precision can be read using GetSystemTimeAdjustment().
The elapsed time retrieved by GetTickCount() or GetTickCount64()
includes time the system spends in sleep or hibernation.
@ -939,6 +938,8 @@ CLOCK_HIGHRES is the nonadjustable, high-resolution clock. For timers
created with a clockid_t value of CLOCK_HIGHRES, the system will
attempt to use an optimal hardware source.
The precision of CLOCK_HIGHRES can be read using ``clock_getres()``.
Solaris: gethrtime
^^^^^^^^^^^^^^^^^^
@ -965,6 +966,7 @@ System time clocks
Name Resolution Include sleep
========================= =============== =============
CLOCK_REALTIME 1 ns Yes
CLOCK_REALTIME_COARSE 1 ns Yes
GetSystemTimeAsFileTime 100 ns Yes
gettimeofday() 1 µs Yes
ftime() 1 ms Yes
@ -980,18 +982,10 @@ CLOCK_REALTIME SunOS 5.11 10 ms 2 µs
CLOCK_REALTIME Linux 3.2 1 ns 2 µs
CLOCK_REALTIME FreeBSD 8.2 11 ns 7 µs
CLOCK_REALTIME OpenBSD 5.0 10 ms 10 µs
CLOCK_REALTIME_COARSE Linux 3.3 1 ms 1 ms
GetSystemTimeAsFileTime Windows Seven 16 ms 1 ms
========================= ================ ========= ===================
For CLOCK_REALTIME, 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.
.. note::
Linux provides also CLOCK_REALTIME_COARSE since Linux 2.6.32 which
has less accurate than CLOCK_REALTIME but is faster.
Windows: GetSystemTimeAsFileTime
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -1008,12 +1002,16 @@ The system time can be set using SetSystemTime().
System time on UNIX
^^^^^^^^^^^^^^^^^^^
gettimeofday(), ftime(), time() and clock_gettime(CLOCK_REALTIME)
return the system clock.
gettimeofday(), ftime(), time() and clock_gettime(CLOCK_REALTIME) return
the system clock. The precision of CLOCK_REALTIME can be read using
clock_getres().
The system time can be set using settimeofday() or
clock_settime(CLOCK_REALTIME).
Linux provides also CLOCK_REALTIME_COARSE since Linux 2.6.32. It is similar
to CLOCK_REALTIME, less precise but faster.
Alexander Shishkin proposed an API for Linux to be notified when the system
clock is changed: `timerfd: add TFD_NOTIFY_CLOCK_SET to watch for clock changes
<http://lwn.net/Articles/432395/>`_ (4th version of the API, March 2011). The
@ -1058,23 +1056,14 @@ GetProcessTimes() Windows Seven 16 ms 16 ms
clock() SunOS 5.11 1 µs 10 ms
========================= ================ ========= ===================
The precision of clock() in this table is the result of 1 /
CLOCKS_PER_SEC. The precision of times() in this table is the result of 1 /
HZ. HZ is a constant or read from sysconf(_SC_CLK_TCK). For
CLOCK_PROCESS_CPUTIME_ID, 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 GetProcessTimes(), the precision is read
using GetSystemTimeAdjustment().
Functions
^^^^^^^^^
* Windows: GetProcessTimes(). The precision can be read using
GetSystemTimeAdjustment().
* clock_gettime(CLOCK_PROCESS_CPUTIME_ID): High-resolution per-process
timer from the CPU.
* clock():
timer from the CPU. The precision can be read using clock_getres().
* clock(). The precision is 1 / CLOCKS_PER_SEC.
* Windows: The elapsed wall-clock time since the start of the
process (elapsed time in seconds times CLOCKS_PER_SEC). It can
@ -1082,8 +1071,10 @@ Functions
* UNIX: returns an approximation of processor time used by the
program.
* times()
* getrusage(RUSAGE_SELF): ru_utime and ru_stime fields
* getrusage(RUSAGE_SELF) returns a structure of resource usage of the currenet
process. ru_utime is use CPU time and ru_stime is the system CPU time.
* times(): structure of process times. The precision is 1 / ticks_per_seconds,
where ticks_per_seconds is sysconf(_SC_CLK_TCK) or the HZ constant.
Python source code includes a portable library to get the process time (CPU
time): `Tools/pybench/systimes.py
@ -1113,10 +1104,6 @@ CLOCK_THREAD_CPUTIME_ID Linux 3.2 1 ns 6
GetThreadTimes() Windows Seven 16 ms 16 ms
========================= ================ =============== ===================
For CLOCK_THREAD_CPUTIME_ID, the precision of this table is the result
of clock_getres(). It looks like Linux does not implement
clock_getres() and always return 1 nanosecond. For GetThreadTimes(),
the precision is read using GetSystemTimeAdjustment().
Functions
^^^^^^^^^
@ -1124,7 +1111,7 @@ Functions
* Windows: GetThreadTimes(). The precision can be read using
GetSystemTimeAdjustment().
* clock_gettime(CLOCK_THREAD_CPUTIME_ID): Thread-specific CPU-time
clock.
clock. The precision can be read using of clock_getres().
See also pthread_getcpuclockid().

View File

@ -52,4 +52,6 @@ for clock_id_text in clock_ids:
def gettime():
return time.clock_gettime(clock_id)
test_clock(name, gettime)
precision = time.clock_getres(clock_id)
print("- announced precision: %s" % format_duration(precision))