PEP 418: Rename time.highres() to time.perf_counter()
This commit is contained in:
parent
f6c80084f7
commit
ab8cded54c
33
pep-0418.txt
33
pep-0418.txt
|
@ -13,7 +13,7 @@ Python-Version: 3.3
|
|||
Abstract
|
||||
========
|
||||
|
||||
Add time.steady(), time.highres(), time.get_clock_info(name) functions to
|
||||
Add time.steady(), time.perf_counter(), time.get_clock_info(name) functions to
|
||||
Python 3.3.
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ Use cases:
|
|||
* Display the current time to a human (e.g. display a calendar or draw
|
||||
a wall clock): use system clock, i.e. time.time() or
|
||||
datetime.datetime.now().
|
||||
* Benchmark, profiling: time.highres().
|
||||
* Benchmark, profiling: time.perf_counter().
|
||||
* Event scheduler, timeout: time.steady().
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ Functions
|
|||
To fulfill the use cases, the functions' properties are:
|
||||
|
||||
* time.time(): system clock, "wall clock".
|
||||
* time.highres(): clock with the best accuracy.
|
||||
* time.perf_counter(): clock with the best accuracy.
|
||||
* time.steady(): steady clock, should be monotonic
|
||||
* time.get_clock_info(name): get information on the specified time function
|
||||
|
||||
|
@ -165,8 +165,8 @@ many issues.
|
|||
different in two Python processes.
|
||||
|
||||
|
||||
time.highres()
|
||||
--------------
|
||||
time.perf_counter()
|
||||
-------------------
|
||||
|
||||
Clock with the best available resolution.
|
||||
|
||||
|
@ -174,24 +174,24 @@ It is available on all platforms and cannot fail.
|
|||
|
||||
Pseudo-code::
|
||||
|
||||
def highres():
|
||||
if highres.use_performance_counter:
|
||||
def perf_counter():
|
||||
if perf_counter.use_performance_counter:
|
||||
try:
|
||||
return _time.QueryPerformanceCounter()
|
||||
except OSError:
|
||||
# QueryPerformanceFrequency() may fail, if the installed
|
||||
# hardware does not support a high-resolution performance
|
||||
# counter for example
|
||||
highres.use_performance_counter = False
|
||||
if highres.use_steady:
|
||||
perf_counter.use_performance_counter = False
|
||||
if perf_counter.use_steady:
|
||||
# Monotonic clock is preferred over system clock
|
||||
try:
|
||||
return time.steady()
|
||||
except OSError:
|
||||
highres.use_steady = False
|
||||
perf_counter.use_steady = False
|
||||
return time.time()
|
||||
highres.use_performance_counter = (os.name == 'nt')
|
||||
highres.use_steady = hasattr(time, 'steady')
|
||||
perf_counter.use_performance_counter = (os.name == 'nt')
|
||||
perf_counter.use_steady = hasattr(time, 'steady')
|
||||
|
||||
time.get_clock_info(name)
|
||||
-------------------------
|
||||
|
@ -199,7 +199,7 @@ time.get_clock_info(name)
|
|||
Get information on the specified clock. Supported clocks:
|
||||
|
||||
* "clock": time.clock()
|
||||
* "highres": time.highres()
|
||||
* "perf_counter": time.perf_counter()
|
||||
* "steady": time.steady()
|
||||
* "time": time.time()
|
||||
|
||||
|
@ -794,8 +794,9 @@ Alternatives: API design
|
|||
Other names for new functions
|
||||
-----------------------------
|
||||
|
||||
time.highres():
|
||||
time.perf_counter():
|
||||
|
||||
* time.highres()
|
||||
* time.hires(): "hires" can be read as "to hire" as in "he hires a car
|
||||
to go on holiday", rather than a "HIgh-RESolution clock".
|
||||
* time.timer(): "it would be too easy to confuse with (or misspell as)
|
||||
|
@ -827,8 +828,8 @@ Don't fallback on system clock
|
|||
time.monotonic() is always a monotonic clock and is only available if the
|
||||
operating system provides a monotonic clock.
|
||||
|
||||
time.highres() is only available if the operating system provides a clock with
|
||||
a high resolution (e.g. at least a microsecond or better).
|
||||
time.perf_counter() is only available if the operating system provides a clock
|
||||
with a high resolution (e.g. at least a microsecond or better).
|
||||
|
||||
|
||||
One function choosing the clock from a list of constrains
|
||||
|
|
Loading…
Reference in New Issue