PEP 418: Add precision in Python of FreeBSD clocks
This commit is contained in:
parent
5837b185c5
commit
165038702e
33
pep-0418.txt
33
pep-0418.txt
|
@ -678,8 +678,8 @@ NTP has different methods to adjust a clock:
|
||||||
|
|
||||||
* "slewing": change the clock frequency to be slightly faster or
|
* "slewing": change the clock frequency to be slightly faster or
|
||||||
slower (which is done with ``adjtime()``). Since the slew rate is
|
slower (which is done with ``adjtime()``). Since the slew rate is
|
||||||
limited to 0.5 ms/s, each second of adjustment requires an
|
limited to 0.5 millisecond per second, each second of adjustment requires an
|
||||||
amortization interval of 2000 s. Thus, an adjustment of many
|
amortization interval of 2000 seconds. Thus, an adjustment of many
|
||||||
seconds can take hours or days to amortize.
|
seconds can take hours or days to amortize.
|
||||||
* "stepping": jump by a large amount in a single discrete step (which
|
* "stepping": jump by a large amount in a single discrete step (which
|
||||||
is done with ``settimeofday()``)
|
is done with ``settimeofday()``)
|
||||||
|
@ -713,6 +713,7 @@ CLOCK_HIGHRES 1 ns No Yes ?
|
||||||
CLOCK_MONOTONIC 1 ns Slewed on Linux Yes No
|
CLOCK_MONOTONIC 1 ns Slewed on Linux Yes No
|
||||||
CLOCK_MONOTONIC_RAW 1 ns No Yes No
|
CLOCK_MONOTONIC_RAW 1 ns No Yes No
|
||||||
CLOCK_BOOTTIME 1 ns ? Yes Yes
|
CLOCK_BOOTTIME 1 ns ? Yes Yes
|
||||||
|
CLOCK_UPTIME 1 ns No Yes ?
|
||||||
mach_absolute_time() 1 ns No Yes No
|
mach_absolute_time() 1 ns No Yes No
|
||||||
QueryPerformanceCounter() \- No Yes ?
|
QueryPerformanceCounter() \- No Yes ?
|
||||||
GetTickCount[64]() 1 ms No Yes Yes
|
GetTickCount[64]() 1 ms No Yes Yes
|
||||||
|
@ -724,14 +725,15 @@ Examples of clock precision on x86_64:
|
||||||
========================= ================ ========= ===================
|
========================= ================ ========= ===================
|
||||||
Name Operating system Precision Precision in Python
|
Name Operating system Precision Precision in Python
|
||||||
========================= ================ ========= ===================
|
========================= ================ ========= ===================
|
||||||
CLOCK_MONOTONIC_RAW Linux 3.2 1 ns 3.0 µs
|
CLOCK_MONOTONIC_RAW Linux 3.2 1 ns 3 µs
|
||||||
CLOCK_MONOTONIC Linux 3.2 1 ns 1.6 µs
|
CLOCK_MONOTONIC Linux 3.2 1 ns 2 µs
|
||||||
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 Seven 10 ns ?
|
QueryPerformanceCounter Windows Seven 10 ns ?
|
||||||
CLOCK_MONOTONIC FreeBSD 8.2 11 ns ?
|
CLOCK_UPTIME FreeBSD 8.2 11 ns 9 µs
|
||||||
|
CLOCK_MONOTONIC FreeBSD 8.2 11 ns 7 µs
|
||||||
CLOCK_MONOTONIC OpenBSD 5.0 10 ms ?
|
CLOCK_MONOTONIC OpenBSD 5.0 10 ms ?
|
||||||
GetTickCount Windows Seven 15.6 ms ?
|
GetTickCount Windows Seven 16 ms ?
|
||||||
========================= ================ ========= ===================
|
========================= ================ ========= ===================
|
||||||
|
|
||||||
For CLOCK_xxx clocks, the precision of this table is the result of
|
For CLOCK_xxx clocks, the precision of this table is the result of
|
||||||
|
@ -974,11 +976,11 @@ Examples of clock precision on x86_64:
|
||||||
========================= ================ ========= ===================
|
========================= ================ ========= ===================
|
||||||
Name Operating system Precision Precision in Python
|
Name Operating system Precision Precision in Python
|
||||||
========================= ================ ========= ===================
|
========================= ================ ========= ===================
|
||||||
CLOCK_REALTIME Linux 3.2 1 ns 1.9 µs
|
CLOCK_REALTIME Linux 3.2 1 ns 2 µs
|
||||||
CLOCK_REALTIME FreeBSD 8.2 11 ns ?
|
CLOCK_REALTIME FreeBSD 8.2 11 ns 7 µs
|
||||||
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 Seven 15.6 ms ?
|
GetSystemTimeAsFileTime Windows Seven 16 ms ?
|
||||||
========================= ================ ========= ===================
|
========================= ================ ========= ===================
|
||||||
|
|
||||||
For CLOCK_REALTIME, the precision of this table is the result of
|
For CLOCK_REALTIME, the precision of this table is the result of
|
||||||
|
@ -1042,14 +1044,15 @@ Examples of clock precision on x86_64:
|
||||||
========================= ================ ========= ===================
|
========================= ================ ========= ===================
|
||||||
Name Operating system Precision Precision in Python
|
Name Operating system Precision Precision in Python
|
||||||
========================= ================ ========= ===================
|
========================= ================ ========= ===================
|
||||||
CLOCK_PROCESS_CPUTIME_ID Linux 3.2 1 ns 3.3 µs
|
CLOCK_PROCESS_CPUTIME_ID Linux 3.2 1 ns 3 µs
|
||||||
clock() SunOS 5.11 1 µs ?
|
clock() SunOS 5.11 1 µs ?
|
||||||
getrusage() Linux 3.0 4 ms 4 ms
|
getrusage() Linux 3.0 4 ms 4 ms
|
||||||
clock() FreeBSD 8.2 7.8 ms ?
|
getrusage() FreeBSD 8.2 - 1 µs
|
||||||
|
clock() FreeBSD 8.2 8 ms 8 ms
|
||||||
clock() Linux 3.2 1 µs 10 ms
|
clock() Linux 3.2 1 µs 10 ms
|
||||||
times() Linux 3.0 10 ms 10 ms
|
times() Linux 3.0 10 ms 10 ms
|
||||||
clock() OpenBSD 5.0 10 ms ?
|
clock() OpenBSD 5.0 10 ms ?
|
||||||
GetProcessTimes() Windows Seven 15.6 ms ?
|
GetProcessTimes() Windows Seven 16 ms ?
|
||||||
========================= ================ ========= ===================
|
========================= ================ ========= ===================
|
||||||
|
|
||||||
The precision of clock() in this table is the result of 1 /
|
The precision of clock() in this table is the result of 1 /
|
||||||
|
@ -1102,9 +1105,9 @@ Examples of clock precision on x86_64:
|
||||||
========================= ================ =============== ===================
|
========================= ================ =============== ===================
|
||||||
Name Operating system Precision Precision in Python
|
Name Operating system Precision Precision in Python
|
||||||
========================= ================ =============== ===================
|
========================= ================ =============== ===================
|
||||||
CLOCK_THREAD_CPUTIME_ID Linux 3.2 1 ns ?
|
CLOCK_THREAD_CPUTIME_ID Linux 3.2 1 ns 6 µs
|
||||||
CLOCK_THREAD_CPUTIME_ID FreeBSD 8.2 1 µs ?
|
CLOCK_THREAD_CPUTIME_ID FreeBSD 8.2 1 µs 1 µs
|
||||||
GetThreadTimes() Windows Seven 15.6 ms ?
|
GetThreadTimes() Windows Seven 16 ms ?
|
||||||
========================= ================ =============== ===================
|
========================= ================ =============== ===================
|
||||||
|
|
||||||
For CLOCK_THREAD_CPUTIME_ID, the precision of this table is the result
|
For CLOCK_THREAD_CPUTIME_ID, the precision of this table is the result
|
||||||
|
|
|
@ -24,11 +24,11 @@ def compute_precision(func):
|
||||||
|
|
||||||
def format_duration(dt):
|
def format_duration(dt):
|
||||||
if dt >= 1e-3:
|
if dt >= 1e-3:
|
||||||
return "%.1f ms" % (dt * 1e3)
|
return "%.0f ms" % (dt * 1e3)
|
||||||
if dt >= 1e-6:
|
if dt >= 1e-6:
|
||||||
return "%.1f µs" % (dt * 1e6)
|
return "%.0f µs" % (dt * 1e6)
|
||||||
else:
|
else:
|
||||||
return "%.1f ns" % (dt * 1e9)
|
return "%.0f ns" % (dt * 1e9)
|
||||||
|
|
||||||
def test_clock(name, func):
|
def test_clock(name, func):
|
||||||
precision = compute_precision(func)
|
precision = compute_precision(func)
|
||||||
|
@ -42,7 +42,7 @@ for name in ('clock', 'perf_counter', 'process_time', 'monotonic', 'time'):
|
||||||
info = time.get_clock_info(name)
|
info = time.get_clock_info(name)
|
||||||
if 'precision' in info:
|
if 'precision' in info:
|
||||||
print("- announced precision: %s" % format_duration(info['precision']))
|
print("- announced precision: %s" % format_duration(info['precision']))
|
||||||
print("- function: %s" % info['function'])
|
print("- implementation: %s" % info['implementation'])
|
||||||
print("- resolution: %s" % format_duration(info['resolution']))
|
print("- resolution: %s" % format_duration(info['resolution']))
|
||||||
|
|
||||||
clock_ids = [name for name in dir(time) if name.startswith("CLOCK_")]
|
clock_ids = [name for name in dir(time) if name.startswith("CLOCK_")]
|
||||||
|
|
Loading…
Reference in New Issue