From 571720811b81a4d9f7c312cf3acd5e17693a1594 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 20 Oct 2003 23:38:28 +0000 Subject: Show microseconds, milliseconds or seconds, whichever is most natural, rather than showing weird numbers like 8.4e+03 usec. --- Lib/timeit.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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__": -- cgit v0.12