Why does %timeit loop different number of times?

倾然丶 夕夏残阳落幕 提交于 2019-12-10 12:48:13

问题


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 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?


回答1:


%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



回答2:


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.



来源:https://stackoverflow.com/questions/45374921/why-does-timeit-loop-different-number-of-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!