有没有办法在google colab中查看执行时间和执行状态?

vin*_*nu 12 python google-colaboratory

我正在尝试在 google colab 中运行笔记本。我想知道是否有办法知道单元是否正在运行以及运行单元需要多长时间(以毫秒为单位)

小智 28

您可以执行此操作来获取每个单元格的运行时间(类似于 Jupyter Notebook 的 ExecuteTime 扩展):

!pip install ipython-autotime
%load_ext autotime
Run Code Online (Sandbox Code Playgroud)

这是运行上面代码后的样子: 在此输入图像描述


小智 11

当您将鼠标悬停在代码块上时,您可以看到一种播放按钮,周围有一个圆形进度环,同时它仍在运行。

要跟踪时间,您可以%%timeit在执行块的开头添加,例如

%%timeit
for i in range(1000):
    print(i)
# above is a placeholder for your code
Run Code Online (Sandbox Code Playgroud)

它会给你运行代码块所花费的时间(以毫秒为单位)。或者,您可以%timeit l = [i for i in range(10)] #placeholder for a single line of code获取单行的执行时间。