[Python-checkins] peps: PEP 418: Add the accuracy of process and thread time clocks
victor.stinner
python-checkins at python.org
Tue Apr 3 01:14:31 CEST 2012
http://hg.python.org/peps/rev/c98fcd2b4631
changeset: 4189:c98fcd2b4631
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Apr 03 01:14:28 2012 +0200
summary:
PEP 418: Add the accuracy of process and thread time clocks
files:
pep-0418.txt | 146 ++++++++++++++++++++++++--------------
1 files changed, 90 insertions(+), 56 deletions(-)
diff --git a/pep-0418.txt b/pep-0418.txt
--- a/pep-0418.txt
+++ b/pep-0418.txt
@@ -275,21 +275,18 @@
Monotonic clocks
----------------
-========================= =============== =============== ================ ====================
-Name Resolution Accuracy Adjusted by NTP? Action on suspend
-========================= =============== =============== ================ ====================
-CLOCK_MONOTONIC_RAW 1 ns (*) No Stopped
-gethrtime 1 ns (*) No Not stopped
-CLOCK_HIGHRES 1 ns (*) No ?
-CLOCK_MONOTONIC 1 ns (*) Slewed on Linux Stopped on Linux
-mach_absolute_time() 1 ns (*) No ?
-QueryPerformanceCounter() \- 0.3 ns - 5 ns No Accuracy issue
-GetTickCount[64]() 1 ms 1 ms - 15 ms No Include suspend time
-timeGetTime() 1 ms 1 ms - 15 ms No ?
-========================= =============== =============== ================ ====================
-
-(*) The accuracy of monotonic clocks depends on the operating system
-and the hardware clock.
+========================= =============== ================ ====================
+Name Resolution Adjusted by NTP? Action on suspend
+========================= =============== ================ ====================
+CLOCK_MONOTONIC_RAW 1 ns No Stopped
+gethrtime 1 ns No Not stopped
+CLOCK_HIGHRES 1 ns No ?
+CLOCK_MONOTONIC 1 ns Slewed on Linux Stopped on Linux
+mach_absolute_time() 1 ns No ?
+QueryPerformanceCounter() \- No Accuracy issue
+GetTickCount[64]() 1 ms No Include suspend time
+timeGetTime() 1 ms No ?
+========================= =============== ================ ====================
The resolution is the smallest difference between two timestamps
supported by the format used by the clock. For example,
@@ -306,14 +303,14 @@
========================= ================ ===============
Name Operating system Accuracy
========================= ================ ===============
-CLOCK_MONOTONIC_RAW Linux 3.2 1 ns
-CLOCK_MONOTONIC Linux 3.2 1 ns
-CLOCK_HIGHRES SunOS 5.11 2 ns
-CLOCK_MONOTONIC SunOS 5.11 2 ns
-QueryPerformanceCounter Windows Vista 10 ns
-CLOCK_MONOTONIC FreeBSD 8.2 11 ns
-CLOCK_MONOTONIC OpenBSD 5.0 10 ms
-GetTickCount Windows Vista 15.6 ms
+CLOCK_MONOTONIC_RAW Linux 3.2 1 ns
+CLOCK_MONOTONIC Linux 3.2 1 ns
+CLOCK_HIGHRES SunOS 5.11 2 ns
+CLOCK_MONOTONIC SunOS 5.11 2 ns
+QueryPerformanceCounter Windows Seven 10 ns
+CLOCK_MONOTONIC FreeBSD 8.2 11 ns
+CLOCK_MONOTONIC OpenBSD 5.0 10 ms
+GetTickCount Windows Seven 15.6 ms
========================= ================ ===============
For CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW, the accuracy of this table is the
@@ -533,18 +530,15 @@
System time clocks
------------------
-========================= =============== ===============
-Name Resolution Accuracy
-========================= =============== ===============
-CLOCK_REALTIME 1 ns (*)
-GetSystemTimeAsFileTime 100 ns 1 ms - 15 ms
-gettimeofday() 1 µs (*)
-ftime() 1 ms (*)
-time() 1 sec 1 sec
-========================= =============== ===============
-
-(*) The accuracy of system clocks depends on the operating system and
-the hardware clock.
+========================= ===============
+Name Resolution
+========================= ===============
+CLOCK_REALTIME 1 ns
+GetSystemTimeAsFileTime 100 ns
+gettimeofday() 1 µs
+ftime() 1 ms
+time() 1 sec
+========================= ===============
Examples of clock accuracy on x86_64:
@@ -555,7 +549,7 @@
CLOCK_REALTIME FreeBSD 8.2 11 ns
CLOCK_REALTIME SunOS 5.11 10 ms
CLOCK_REALTIME OpenBSD 5.0 10 ms
-GetSystemTimeAsFileTime Windows Vista 15.6 ms
+GetSystemTimeAsFileTime Windows Seven 15.6 ms
========================= ================ ===============
For CLOCK_REALTIME, the accuracy of this table is the result of clock_getres().
@@ -587,7 +581,7 @@
Resolution:
-* clock_gettime(): clock_getres(CLOCK_REALTIME), 1 nanosecond on Linux
+* clock_gettime(): clock_getres(CLOCK_REALTIME)
* gettimeofday(): 1 microsecond
* ftime(): 1 millisecond
* time(): 1 second
@@ -596,14 +590,41 @@
clock_settime(CLOCK_REALTIME).
-Process and thread time
------------------------
+Process time
+------------
-The process and thread time cannot be set. They are not monotonic:
-the clocks stop while the process/thread is idle.
+The process time cannot be set. It is not monotonic: the clocks stop while the
+process is idle.
-Process
-^^^^^^^
+========================= ===============
+Name Resolution
+========================= ===============
+GetProcessTimes() 100 ns
+CLOCK_PROCESS_CPUTIME_ID 1 ns
+clock() \-
+========================= ===============
+
+Examples of clock accuracy on x86_64:
+
+========================= ================ ===============
+Name Operating system Accuracy
+========================= ================ ===============
+CLOCK_PROCESS_CPUTIME_ID Linux 3.2 1 ns
+clock() Linux 3.2 1 µs
+clock() SunOS 5.11 1 µs
+clock() FreeBSD 8.2 7.8 ms
+clock() OpenBSD 5.0 10 ms
+GetProcessTimes() Windows Seven 15.6 ms
+========================= ================ ===============
+
+The accuracy of clock() in this table is the result of 1 / CLOCKS_PER_SEC.
+For CLOCK_PROCESS_CPUTIME_ID, the accuracy of this table is the result of
+clock_getres(). It looks like Linux does not implement clock_getres() and
+always return 1 nanosecond. For GetProcessTimes(), the accuracy is read using
+GetSystemTimeAdjustment().
+
+Functions
+^^^^^^^^^
* Windows: GetProcessTimes()
* clock_gettime(CLOCK_PROCESS_CPUTIME_ID): High-resolution per-process
@@ -622,28 +643,41 @@
Resolution:
* clock() rate is CLOCKS_PER_SEC. It was called CLK_TCK in Microsoft
- C before 6.0. On Linux 3, clock() has a resolution of 1
- microsecond.
+ C before 6.0.
* The clock resolution can be read using clock_getres().
- clock_getres(CLOCK_REALTIME) is 1 nanosecond on Linux.
* GetProcessTimes(): call GetSystemTimeAdjustment().
+
+Thread time
+-----------
+
+The thread time cannot be set. It is not monotonic: the clocks stop while the
+thread is idle.
+
+========================= ===============
+Name Resolution
+========================= ===============
+GetThreadTimes() 100 ns
+CLOCK_THREAD_CPUTIME_ID 1 ns
+========================= ===============
+
Examples of clock accuracy on x86_64:
========================= ================ ===============
Name Operating system Accuracy
========================= ================ ===============
-clock() Linux 3.2 1 ms
-clock() SunOS 5.11 1 ms
-clock() FreeBSD 8.2 7.8 ms
-clock() OpenBSD 5.0 10 ms
+CLOCK_THREAD_CPUTIME_ID Linux 3.2 1 ns
+CLOCK_THREAD_CPUTIME_ID FreeBSD 8.2 1 µs
+GetThreadTimes() Windows Seven 15.6 ms
========================= ================ ===============
-The accuracy of clock() in this table is the result of 1 / CLOCKS_PER_SEC.
+For CLOCK_THREAD_CPUTIME_ID, the accuracy 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 accuracy is read using
+GetSystemTimeAdjustment().
-
-Thread
-^^^^^^
+Functions
+^^^^^^^^^
* Windows: GetThreadTimes()
* clock_gettime(CLOCK_THREAD_CPUTIME_ID): Thread-specific CPU-time
@@ -651,15 +685,14 @@
Resolution:
-* CLOCK_THREAD_CPUTIME_ID: call clock_getres(). 1 nanosecond on
- Linux.
+* CLOCK_THREAD_CPUTIME_ID: call clock_getres().
* GetThreadTimes(): call GetSystemTimeAdjustment()
See also pthread_getcpuclockid().
Windows: QueryUnbiasedInterruptTime
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+-----------------------------------
Gets the current unbiased interrupt time from the biased interrupt
time and the current sleep bias amount. This time is not affected by
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list