【问题标题】:How to calculate execution time of a python function? [duplicate]如何计算python函数的执行时间? [复制]
【发布时间】:2020-03-28 12:18:31
【问题描述】:

我正在调用一个函数来从共享点下载文件并上传到 sql server 数据库。 我在表格中记录信息成功和失败。如何计算执行此函数的总时间?

喜欢:

start_time=datetime.now()
function call 
end_time=datetime.now()
total=end_time-start_time

请提出有效的查询,我的时间不多了。

【问题讨论】:

  • 为什么不直接使用已有的示例?

标签: python python-3.x logging execution-time


【解决方案1】:

这里有一个方法来完成它:

代码:

from datetime import datetime

st = datetime.now()

#call your function here

et=datetime.now()
print('\nTotal time for execution : {}'.format(et-st).split(".")[0])

输出:

Total time for execution : 0:00:00

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-01
    • 2021-07-15
    • 2015-07-19
    • 2014-09-05
    • 1970-01-01
    • 2021-08-05
    • 2016-11-15
    • 1970-01-01
    相关资源
    最近更新 更多