summaryrefslogtreecommitdiffstats
path: root/Lib/timeit.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-10-20 23:38:28 (GMT)
committerGuido van Rossum <guido@python.org>2003-10-20 23:38:28 (GMT)
commit571720811b81a4d9f7c312cf3acd5e17693a1594 (patch)
treeb56816b089270e8fa120f88daca6393a3cfcc976 /Lib/timeit.py
parent0c9a318d644c3a5ef0d611cc5a35a5cbd7e7b929 (diff)
downloadcpython-571720811b81a4d9f7c312cf3acd5e17693a1594.zip
cpython-571720811b81a4d9f7c312cf3acd5e17693a1594.tar.gz
cpython-571720811b81a4d9f7c312cf3acd5e17693a1594.tar.bz2
Show microseconds, milliseconds or seconds, whichever is most natural,
rather than showing weird numbers like 8.4e+03 usec.
Diffstat (limited to 'Lib/timeit.py')
-rw-r--r--Lib/timeit.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/timeit.py b/Lib/timeit.py
index 1127aaa..7829395 100644
--- a/Lib/timeit.py
+++ b/Lib/timeit.py
@@ -264,7 +264,15 @@ def main(args=None):
print "raw times:", " ".join(["%.*g" % (precision, x) for x in r])
print "%d loops," % number,
usec = best * 1e6 / number
- print "best of %d: %.*g usec per loop" % (repeat, precision, usec)
+ if usec < 1000:
+ print "best of %d: %.*g usec per loop" % (repeat, precision, usec)
+ else:
+ msec = usec / 1000
+ if msec < 1000:
+ print "best of %d: %.*g msec per loop" % (repeat, precision, msec)
+ else:
+ sec = msec / 1000
+ print "best of %d: %.*g sec per loop" % (repeat, precision, sec)
return None
if __name__ == "__main__":