在ipython Notebook中测量单元执行时间的简单方法 [英] Simple way to measure cell execution time in ipython notebook
问题描述
除了单元的原始输出外,我还想花时间在单元执行上.
I would like to get the time spent on the cell execution in addition to the original output from cell.
为此,我尝试了%%timeit -r1 -n1
,但是它没有公开定义在单元格中的变量.
To this end, I tried %%timeit -r1 -n1
but it doesn't expose the variable defined within cell.
%%time
适用于仅包含1条语句的单元格.
%%time
works for cell which only contains 1 statement.
In[1]: %%time
1
CPU times: user 4 µs, sys: 0 ns, total: 4 µs
Wall time: 5.96 µs
Out[1]: 1
In[2]: %%time
# Notice there is no out result in this case.
x = 1
x
CPU times: user 3 µs, sys: 0 ns, total: 3 µs
Wall time: 5.96 µs
最好的方法是什么?
我一直在使用在Nbextension中执行时间现在已经有一段时间了.太好了.
I have been using Execute Time in Nbextension for quite some time now. It is great.
推荐答案
使用单元魔术和Phillip Cloud在github上创建此项目:
Use cell magic and this project on github by Phillip Cloud:
通过将其放在笔记本顶部或如果您始终希望默认情况下将其放置在配置文件中,可将其放置在配置文件中:
Load it by putting this at the top of your notebook or put it in your config file if you always want to load it by default:
%install_ext https://raw.github.com/cpcloud/ipython-autotime/master/autotime.py
%load_ext autotime
如果加载,则随后的单元执行的每个输出将包括执行时间(以分钟和秒为单位).
If loaded, every output of subsequent cell execution will include the time in min and sec it took to execute it.
这篇关于在ipython Notebook中测量单元执行时间的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!