Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5717208

Browse files
committed
Show microseconds, milliseconds or seconds, whichever is most natural,
rather than showing weird numbers like 8.4e+03 usec.
1 parent 0c9a318 commit 5717208

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Lib/timeit.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,15 @@ def main(args=None):
264264
print "raw times:", " ".join(["%.*g" % (precision, x) for x in r])
265265
print "%d loops," % number,
266266
usec = best * 1e6 / number
267-
print "best of %d: %.*g usec per loop" % (repeat, precision, usec)
267+
if usec < 1000:
268+
print "best of %d: %.*g usec per loop" % (repeat, precision, usec)
269+
else:
270+
msec = usec / 1000
271+
if msec < 1000:
272+
print "best of %d: %.*g msec per loop" % (repeat, precision, msec)
273+
else:
274+
sec = msec / 1000
275+
print "best of %d: %.*g sec per loop" % (repeat, precision, sec)
268276
return None
269277

270278
if __name__ == "__main__":

0 commit comments

Comments
 (0)