mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
Issue #14428: Use the new time.perf_counter() and time.process_time() functions
* Replace "time.clock on windows, or time.time" with time.perf_counter() * profile module: only use time.process_time() instead of trying different functions providing the process time * timeit module: use time.perf_counter() by default, time.time() and time.clock() can still be used using --time and --clock options * pybench program: use time.perf_counter() by default, add support for the new time.process_time() and time.perf_counter() functions, but stay backward compatible. Use also time.get_clock_info() to display information of the timer.
This commit is contained in:
parent
47620a6611
commit
fe98e2fc83
7 changed files with 32 additions and 55 deletions
|
@ -15,8 +15,8 @@ Options:
|
|||
-n/--number N: how many times to execute 'statement' (default: see below)
|
||||
-r/--repeat N: how many times to repeat the timer (default 3)
|
||||
-s/--setup S: statement to be executed once initially (default 'pass')
|
||||
-t/--time: use time.time() (default on Unix)
|
||||
-c/--clock: use time.clock() (default on Windows)
|
||||
-t/--time: use time.time()
|
||||
-c/--clock: use time.clock()
|
||||
-v/--verbose: print raw timing results; repeat for more digits precision
|
||||
-h/--help: print this usage message and exit
|
||||
--: separate options from statement, use when statement starts with -
|
||||
|
@ -66,13 +66,7 @@ __all__ = ["Timer"]
|
|||
dummy_src_name = "<timeit-src>"
|
||||
default_number = 1000000
|
||||
default_repeat = 3
|
||||
|
||||
if sys.platform == "win32":
|
||||
# On Windows, the best timer is time.clock()
|
||||
default_timer = time.clock
|
||||
else:
|
||||
# On most other platforms the best timer is time.time()
|
||||
default_timer = time.time
|
||||
default_timer = time.perf_counter
|
||||
|
||||
# Don't change the indentation of the template; the reindent() calls
|
||||
# in Timer.__init__() depend on setup being indented 4 spaces and stmt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue