怎么计算python程序运行时间

发布时间:2022-06-22 09:40:57 人气:232 作者:多测师

  python脚本使用统计时间的方式是time.clock(),而这种方式统计的是CPU的执行时间,不是程序的执行时间。

  下面我们就来看一下计算python程序运行时间的方法:

  def time_function(f, *args):

  """

怎么计算python程序运行时间

  Call a function f with args and return the time (in seconds) that it took to execute.

  """

  import time

  tic = time.time()

  f(*args)

  toc = time.time()

  return toc - tic

  使用time()返回程序运行时和程序结束的时间戳,然后将两个时间相减即可获得程序运行时间。

  以上内容为大家介绍了怎么计算python程序运行时间,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注多测师。https://www.e70w.com/xwzx/


返回列表
在线客服
联系方式

热线电话

17727591462

上班时间

周一到周五

二维码
线