On Jupter Notebook, i was trying to compare time taken between the two methods for finding the index with max value.
In the Image, the first function took, 1000
It has a built-in option -n: " Options: -n: execute the given statement times in a loop. If this value is not given, a fitting value is chosen."docs
So it choses the number of loops itself if not specified.
use -r
to limit the number of run's:
import time
%timeit -r1 time.sleep(2)
# 2 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)
%timeit -r4 time.sleep(2)
# 2 s ± 800 µs per loop (mean ± std. dev. of 4 runs, 1 loop each)
%timeit time.sleep(2)
# 2 s ± 46.5 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit
library will limit the number of runs depending on how long the script takes to execute.
The number of runs may be set with -n. Example:
%timeit -n 5000
df = pd.DataFrame({'High':[1,4,8,4,0]})
5000 loops, best of 3: 592 µs per loop