Why does %timeit loop different number of times?

Viewed 16667

On Jupter Notebook, i was trying to compare time taken between the two methods for finding the index with max value.

enter image description here

In the Image, the first function took, 1000 loops, and the second took 10000 loops, is this increase in loops due to the method itself OR Jupyter Just added more loops to get more accurate time per loop even though the second function maybe took 1000 only, is that the case?

3 Answers

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)
Related