[Python-checkins] cpython: timeit: add nsec (nanosecond) unit for format timings
victor.stinner
python-checkins at python.org
Tue Oct 18 12:00:13 EDT 2016
https://hg.python.org/cpython/rev/c3a93069111d
changeset: 104541:c3a93069111d
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Oct 18 17:42:48 2016 +0200
summary:
timeit: add nsec (nanosecond) unit for format timings
Issue #28240.
files:
Doc/library/timeit.rst | 2 +-
Lib/test/test_timeit.py | 2 +-
Lib/timeit.py | 6 +++---
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/Doc/library/timeit.rst b/Doc/library/timeit.rst
--- a/Doc/library/timeit.rst
+++ b/Doc/library/timeit.rst
@@ -224,7 +224,7 @@
.. cmdoption:: -u, --unit=U
- specify a time unit for timer output; can select usec, msec, or sec
+ specify a time unit for timer output; can select nsec, usec, msec, or sec
.. versionadded:: 3.5
diff --git a/Lib/test/test_timeit.py b/Lib/test/test_timeit.py
--- a/Lib/test/test_timeit.py
+++ b/Lib/test/test_timeit.py
@@ -331,7 +331,7 @@
invalid = self.run_main(seconds_per_increment=0.002,
switches=['-u', 'parsec'])
self.assertEqual(error_stringio.getvalue(),
- "Unrecognized unit. Please select usec, msec, or sec.\n")
+ "Unrecognized unit. Please select nsec, usec, msec, or sec.\n")
def test_main_exception(self):
with captured_stderr() as error_stringio:
diff --git a/Lib/timeit.py b/Lib/timeit.py
--- a/Lib/timeit.py
+++ b/Lib/timeit.py
@@ -18,7 +18,7 @@
Execution time of this setup statement is NOT timed.
-p/--process: use time.process_time() (default is time.perf_counter())
-v/--verbose: print raw timing results; repeat for more digits precision
- -u/--unit: set the output time unit (usec, msec, or sec)
+ -u/--unit: set the output time unit (nsec, usec, msec, or sec)
-h/--help: print this usage message and exit
--: separate options from statement, use when statement starts with -
statement: statement to be timed (default 'pass')
@@ -272,7 +272,7 @@
repeat = default_repeat
verbose = 0
time_unit = None
- units = {"usec": 1e-6, "msec": 1e-3, "sec": 1.0}
+ units = {"nsec": 1e-9, "usec": 1e-6, "msec": 1e-3, "sec": 1.0}
precision = 3
for o, a in opts:
if o in ("-n", "--number"):
@@ -283,7 +283,7 @@
if a in units:
time_unit = a
else:
- print("Unrecognized unit. Please select usec, msec, or sec.",
+ print("Unrecognized unit. Please select nsec, usec, msec, or sec.",
file=sys.stderr)
return 2
if o in ("-r", "--repeat"):
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list