%%timeit in IPython or Jupyter notebook has 2 features I like.
Run for a limited time, adjust the number of iterations automatically for a given number of batches.
Output is mean + standard deviation. That's nicer than the minimum run time among many runs.
Here is example output from an IPython terminal. The first one is from a "slow version" of a function, the second is from a faster version.
In [21]: %timeit hh = gg.get_map(form="232", year=2019, source="form")
1.82 s ± 111 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [18]: %timeit jj = fm.get_map(form="232", year=2019, source="form")
324 µs ± 22.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
Note that when the function was slow, it gave back 7 x 1 execution times, but when it was fast it dialed up to 7 x 1000.
I've been studying the IPython code to understand how they do that, thinking I could adapt for a block of python code. This is difficult work! It is taking me into unfamiliar territory interacting with AST.
It seems to me like somebody must have done this before. Is there no Python package for this?