找出一个python脚本完成执行所花费的时间 [英] Find out time it took for a python script to complete execution

查看:92
本文介绍了找出一个python脚本完成执行所花费的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python脚本中有以下代码:

I have the following code in a python script:

def fun(): 
  #Code here

fun()

我想执行此脚本并了解如何在几分钟内执行需要很多时间。我如何确定此脚本执行需要花费多少时间?

I want to execute this script and also find out how much time it took to execute in minutes. How do I find out how much time it took for this script to execute ? An example would be really appreciated.

推荐答案

from datetime import datetime
startTime = datetime.now()

#do something

#Python 2: 
print datetime.now() - startTime 

#Python 3: 
print(datetime.now() - startTime)

这篇关于找出一个python脚本完成执行所花费的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆