Skip to content

Commit c3e40f8

Browse files
committed
timeit: add nsec (nanosecond) unit for format timings
Issue #28240.
1 parent 61de57f commit c3e40f8

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

Doc/library/timeit.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Where the following options are understood:
224224

225225
.. cmdoption:: -u, --unit=U
226226

227-
specify a time unit for timer output; can select usec, msec, or sec
227+
specify a time unit for timer output; can select nsec, usec, msec, or sec
228228

229229
.. versionadded:: 3.5
230230

Lib/test/test_timeit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def test_main_with_time_unit(self):
331331
invalid = self.run_main(seconds_per_increment=0.002,
332332
switches=['-u', 'parsec'])
333333
self.assertEqual(error_stringio.getvalue(),
334-
"Unrecognized unit. Please select usec, msec, or sec.\n")
334+
"Unrecognized unit. Please select nsec, usec, msec, or sec.\n")
335335

336336
def test_main_exception(self):
337337
with captured_stderr() as error_stringio:

Lib/timeit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Execution time of this setup statement is NOT timed.
1919
-p/--process: use time.process_time() (default is time.perf_counter())
2020
-v/--verbose: print raw timing results; repeat for more digits precision
21-
-u/--unit: set the output time unit (usec, msec, or sec)
21+
-u/--unit: set the output time unit (nsec, usec, msec, or sec)
2222
-h/--help: print this usage message and exit
2323
--: separate options from statement, use when statement starts with -
2424
statement: statement to be timed (default 'pass')
@@ -272,7 +272,7 @@ def main(args=None, *, _wrap_timer=None):
272272
repeat = default_repeat
273273
verbose = 0
274274
time_unit = None
275-
units = {"usec": 1e-6, "msec": 1e-3, "sec": 1.0}
275+
units = {"nsec": 1e-9, "usec": 1e-6, "msec": 1e-3, "sec": 1.0}
276276
precision = 3
277277
for o, a in opts:
278278
if o in ("-n", "--number"):
@@ -283,7 +283,7 @@ def main(args=None, *, _wrap_timer=None):
283283
if a in units:
284284
time_unit = a
285285
else:
286-
print("Unrecognized unit. Please select usec, msec, or sec.",
286+
print("Unrecognized unit. Please select nsec, usec, msec, or sec.",
287287
file=sys.stderr)
288288
return 2
289289
if o in ("-r", "--repeat"):

0 commit comments

Comments
 (0)