![图片[1]-python如何获取程序执行时间?-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5ec77b38cb67a544.jpg)
python获取程序执行时间的方法:
1、使用time.clock()方法获取程序执行时间
注:python的标准库手册推荐在任何情况下尽量使用time.clock().
使用方法:
importtime
start=time.clock()
#中间写上代码块
end=time.clock()
print('Runningtime:%sSeconds'%(end-start))
2、使用time.time()方法计算
importtime
start=time.time()
#中间写上代码块
end=time.time()
print('Runningtime:%sSeconds'%(end-start))
3、使用datetime.datetime.now()方法获取
importdatetime
start=datetime.datetime.now()
#中间写代码块
end=datetime.datetime.now()
print('Runningtime:%sSeconds'%(end-start))原文来自:https://www.py.cn © 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END



















































暂无评论内容