PEP 418: Add the accuracy of process and thread time clocks

This commit is contained in:
Victor Stinner 2012-04-03 01:14:28 +02:00
parent 7ba7cc657f
commit f0107e6f66
1 changed files with 90 additions and 57 deletions

View File

@ -275,21 +275,18 @@ Operating system clocks
Monotonic clocks Monotonic clocks
---------------- ----------------
========================= =============== =============== ================ ==================== ========================= =============== ================ ====================
Name Resolution Accuracy Adjusted by NTP? Action on suspend Name Resolution Adjusted by NTP? Action on suspend
========================= =============== =============== ================ ==================== ========================= =============== ================ ====================
CLOCK_MONOTONIC_RAW 1 ns (*) No Stopped CLOCK_MONOTONIC_RAW 1 ns No Stopped
gethrtime 1 ns (*) No Not stopped gethrtime 1 ns No Not stopped
CLOCK_HIGHRES 1 ns (*) No ? CLOCK_HIGHRES 1 ns No ?
CLOCK_MONOTONIC 1 ns (*) Slewed on Linux Stopped on Linux CLOCK_MONOTONIC 1 ns Slewed on Linux Stopped on Linux
mach_absolute_time() 1 ns (*) No ? mach_absolute_time() 1 ns No ?
QueryPerformanceCounter() \- 0.3 ns - 5 ns No Accuracy issue QueryPerformanceCounter() \- No Accuracy issue
GetTickCount[64]() 1 ms 1 ms - 15 ms No Include suspend time GetTickCount[64]() 1 ms No Include suspend time
timeGetTime() 1 ms 1 ms - 15 ms No ? timeGetTime() 1 ms No ?
========================= =============== =============== ================ ==================== ========================= =============== ================ ====================
(*) The accuracy of monotonic clocks depends on the operating system
and the hardware clock.
The resolution is the smallest difference between two timestamps The resolution is the smallest difference between two timestamps
supported by the format used by the clock. For example, supported by the format used by the clock. For example,
@ -306,14 +303,14 @@ Examples of clock accuracy on x86_64:
========================= ================ =============== ========================= ================ ===============
Name Operating system Accuracy Name Operating system Accuracy
========================= ================ =============== ========================= ================ ===============
CLOCK_MONOTONIC_RAW Linux 3.2 1 ns CLOCK_MONOTONIC_RAW Linux 3.2 1 ns
CLOCK_MONOTONIC Linux 3.2 1 ns CLOCK_MONOTONIC Linux 3.2 1 ns
CLOCK_HIGHRES SunOS 5.11 2 ns CLOCK_HIGHRES SunOS 5.11 2 ns
CLOCK_MONOTONIC SunOS 5.11 2 ns CLOCK_MONOTONIC SunOS 5.11 2 ns
QueryPerformanceCounter Windows Vista 10 ns QueryPerformanceCounter Windows Seven 10 ns
CLOCK_MONOTONIC FreeBSD 8.2 11 ns CLOCK_MONOTONIC FreeBSD 8.2 11 ns
CLOCK_MONOTONIC OpenBSD 5.0 10 ms CLOCK_MONOTONIC OpenBSD 5.0 10 ms
GetTickCount Windows Vista 15.6 ms GetTickCount Windows Seven 15.6 ms
========================= ================ =============== ========================= ================ ===============
For CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW, the accuracy of this table is the For CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW, the accuracy of this table is the
@ -533,18 +530,15 @@ On Solaris, gethrtime() is the same as clock_gettime(CLOCK_MONOTONIC).
System time clocks System time clocks
------------------ ------------------
========================= =============== =============== ========================= ===============
Name Resolution Accuracy Name Resolution
========================= =============== =============== ========================= ===============
CLOCK_REALTIME 1 ns (*) CLOCK_REALTIME 1 ns
GetSystemTimeAsFileTime 100 ns 1 ms - 15 ms GetSystemTimeAsFileTime 100 ns
gettimeofday() 1 µs (*) gettimeofday() 1 µs
ftime() 1 ms (*) ftime() 1 ms
time() 1 sec 1 sec time() 1 sec
========================= =============== =============== ========================= ===============
(*) The accuracy of system clocks depends on the operating system and
the hardware clock.
Examples of clock accuracy on x86_64: Examples of clock accuracy on x86_64:
@ -555,7 +549,7 @@ CLOCK_REALTIME Linux 3.2 1 ns
CLOCK_REALTIME FreeBSD 8.2 11 ns CLOCK_REALTIME FreeBSD 8.2 11 ns
CLOCK_REALTIME SunOS 5.11 10 ms CLOCK_REALTIME SunOS 5.11 10 ms
CLOCK_REALTIME OpenBSD 5.0 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(). For CLOCK_REALTIME, the accuracy of this table is the result of clock_getres().
@ -587,7 +581,7 @@ return the system clock.
Resolution: Resolution:
* clock_gettime(): clock_getres(CLOCK_REALTIME), 1 nanosecond on Linux * clock_gettime(): clock_getres(CLOCK_REALTIME)
* gettimeofday(): 1 microsecond * gettimeofday(): 1 microsecond
* ftime(): 1 millisecond * ftime(): 1 millisecond
* time(): 1 second * time(): 1 second
@ -596,14 +590,41 @@ The system time can be set using settimeofday() or
clock_settime(CLOCK_REALTIME). clock_settime(CLOCK_REALTIME).
Process and thread time Process time
----------------------- ------------
The process and thread time cannot be set. They are not monotonic: The process time cannot be set. It is not monotonic: the clocks stop while the
the clocks stop while the process/thread is idle. 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() * Windows: GetProcessTimes()
* clock_gettime(CLOCK_PROCESS_CPUTIME_ID): High-resolution per-process * clock_gettime(CLOCK_PROCESS_CPUTIME_ID): High-resolution per-process
@ -622,28 +643,41 @@ Process
Resolution: Resolution:
* clock() rate is CLOCKS_PER_SEC. It was called CLK_TCK in Microsoft * 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 C before 6.0.
microsecond.
* The clock resolution can be read using clock_getres(). * The clock resolution can be read using clock_getres().
clock_getres(CLOCK_REALTIME) is 1 nanosecond on Linux.
* GetProcessTimes(): call GetSystemTimeAdjustment(). * 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: Examples of clock accuracy on x86_64:
========================= ================ =============== ========================= ================ ===============
Name Operating system Accuracy Name Operating system Accuracy
========================= ================ =============== ========================= ================ ===============
clock() Linux 3.2 1 ms CLOCK_THREAD_CPUTIME_ID Linux 3.2 1 ns
clock() SunOS 5.11 1 ms CLOCK_THREAD_CPUTIME_ID FreeBSD 8.2 1 µs
clock() FreeBSD 8.2 7.8 ms GetThreadTimes() Windows Seven 15.6 ms
clock() OpenBSD 5.0 10 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().
Functions
Thread ^^^^^^^^^
^^^^^^
* Windows: GetThreadTimes() * Windows: GetThreadTimes()
* clock_gettime(CLOCK_THREAD_CPUTIME_ID): Thread-specific CPU-time * clock_gettime(CLOCK_THREAD_CPUTIME_ID): Thread-specific CPU-time
@ -651,15 +685,14 @@ Thread
Resolution: Resolution:
* CLOCK_THREAD_CPUTIME_ID: call clock_getres(). 1 nanosecond on * CLOCK_THREAD_CPUTIME_ID: call clock_getres().
Linux.
* GetThreadTimes(): call GetSystemTimeAdjustment() * GetThreadTimes(): call GetSystemTimeAdjustment()
See also pthread_getcpuclockid(). See also pthread_getcpuclockid().
Windows: QueryUnbiasedInterruptTime Windows: QueryUnbiasedInterruptTime
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -----------------------------------
Gets the current unbiased interrupt time from the biased interrupt Gets the current unbiased interrupt time from the biased interrupt
time and the current sleep bias amount. This time is not affected by time and the current sleep bias amount. This time is not affected by