PEP 418: Rename time.highres() to time.perf_counter()

This commit is contained in:
Victor Stinner 2012-04-04 01:09:35 +02:00
parent f6c80084f7
commit ab8cded54c
1 changed files with 17 additions and 16 deletions

View File

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