【发布时间】:2015-12-10 12:22:16
【问题描述】:
除了单元格的原始输出之外,我还想获取单元格执行所花费的时间。
为此,我尝试了%%timeit -r1 -n1,但它没有公开单元格中定义的变量。
%%time 适用于仅包含 1 条语句的单元格。
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
最好的方法是什么?
更新
我使用Execute Time in Nbextension 已经有一段时间了。太棒了。
2021 年 3 月更新
截至目前,this 是正确答案。从本质上讲,%%time 和 %%timeit 现在都可以正常工作了。
【问题讨论】:
-
你真的需要计时值的显示吗?为什么不把
x显示行放在下一个单元格中? -
为什么不接受答案?
标签: python jupyter-notebook ipython jupyter