pythonpandasipythonjupyter-notebookjupyter

Why does %timeit loop different number of times?


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?


Solution

  • %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