发布时间:2022-06-06 09:38:13 人气:18 作者:多测师
python获取程序执行时间的方法:
1、使用time.clock()方法获取程序执行时间
注:python的标准库手册推荐在任何情况下尽量使用time.clock().
使用方法:
import time
start =time.clock()
#中间写上代码块
end = time.clock()
print('Running time: %s Seconds'%(end-start))
2、使用time.time()方法计算
import time
start=time.time()
#中间写上代码块
end=time.time()
print('Running time: %s Seconds'%(end-start))
3、使用datetime.datetime.now()方法获取
import datetime
start=datetime.datetime.now()
#中间写代码块
end=datetime.datetime.now()
print('Running time: %s Seconds'%(end-start))
以上内容为大家介绍了python如何获取程序执行时间?希望对大家有所帮助,如果想要了解更多Python相关知识,请关注多测师。https://www.e70w.com/xwzx/