]> granicus.if.org Git - python/commitdiff
Show microseconds, milliseconds or seconds, whichever is most natural,
authorGuido van Rossum <guido@python.org>
Mon, 20 Oct 2003 23:38:28 +0000 (23:38 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 20 Oct 2003 23:38:28 +0000 (23:38 +0000)
rather than showing weird numbers like 8.4e+03 usec.

Lib/timeit.py

index 1127aaae40534eade1fa6d925480b33595db713d..7829395266623b0548e0595f9797084eddb8b1ea 100644 (file)
@@ -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__":