From 1a1bcdc2f6d91f3496bdae2047359020e0817066 2009-04-14 06:07:43 From: Prabhu Ramachandran Date: 2009-04-14 06:07:43 Subject: [PATCH] Fix %timeit for slow functions, by Prabhu Ramachandran. From his submission on the list: Lets say you have a function that takes 2 seconds to evaluate. With the original code you are going to run that function 10 times regardless of the fact that it already takes 2 seconds and with the original code, timing this will take at least 60 seconds (with repeat=3) which is way too much. --- diff --git a/IPython/Magic.py b/IPython/Magic.py index 6da7184..3cf390d 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1865,9 +1865,9 @@ Currently the magic system has the following functions:\n""" # determine number so that 0.2 <= total time < 2.0 number = 1 for i in range(1, 10): - number *= 10 if timer.timeit(number) >= 0.2: break + number *= 10 best = min(timer.repeat(repeat, number)) / number