为什么%timeit循环次数不同? [英] Why does %timeit loop different number of times?

查看:394
本文介绍了为什么%timeit循环次数不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jupter Notebook上,我试图比较两种方法之间的时间来找到最大值的索引。

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

在Image中,第一个函数占用了1000个循环,第二个函数占用了10000个循环,这是因为方法本身的循环增加或者Jupyter Just添加了更多循环以获得更准确的每个循环时间,即使第二个函数可能只需要1000个,是这样吗?

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?

推荐答案

%timeit 库将限制运行次数,具体取决于脚本执行的时间。

%timeit library will limit the number of runs depending on how long the script takes to execute.

运行次数可以用-n设置。示例:

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

这篇关于为什么%timeit循环次数不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆