有没有一种方法可以将单元格的执行时间存储在变量中?

时间:2020-09-28 10:05:54

标签: python jupyter-notebook google-colaboratory

尽管ipython-autotime包可以使用以下代码显示每个单元格的运行时间

!pip install ipython-autotime %load_ext autotime

我找不到将其存储在变量中的方法。

我试图找到一种方法来将所有单元格的运行时间存储到变量中,并最终导出这些值以进行制表。

1 个答案:

答案 0 :(得分:0)

您可以使用时间模块执行相同的任务,但以不同的方式。

import time

#at the start of cell, define <tic> variable
tic = time.time()

"""Write your python logic here"""

print("hello world")

"""Your logic ends here"""

#at the end of cell, define <toc> variable
toc = time.time()

#store execution time in variable. Note the unit of the result is seconds
time_taken = toc - tic 
相关问题