有时我执行一个需要很长时间才能计算的方法
In [1]:
long_running_invocation()
Out[1]:
Run Code Online (Sandbox Code Playgroud)
我常常有兴趣知道花了多少时间,所以我必须写下这个:
In[2]:
import time
start = time.time()
long_running_invocation()
end = time.time()
print end - start
Out[2]: 1024
Run Code Online (Sandbox Code Playgroud)
有没有办法配置我的IPython笔记本,以便它自动打印我正在制作的每个调用的执行时间,如下例所示?
In [1]:
long_running_invocation()
Out[1] (1.59s):
Run Code Online (Sandbox Code Playgroud)
这个ipython扩展可以满足您的需求:https://github.com/cpcloud/ipython-autotime
通过将它放在笔记本的顶部来加载它:
%install_ext https://raw.github.com/cpcloud/ipython-autotime/master/autotime.py
%load_ext autotime
加载后,每个后续单元格执行将包括作为其输出的一部分执行所花费的时间.
| 归档时间: |
|
| 查看次数: |
1780 次 |
| 最近记录: |