这篇文章将为大家详细讲解有关python获取程序执行时间的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

python获取程序执行时间的方法:

1、使用time.clock()方法获取程序执行时间

注:python的标准库手册推荐在任何情况下尽量使用time.clock().

使用方法:

importtimestart=time.clock()#中间写上代码块end=time.clock()print('Runningtime:%sSeconds'%(end-start))

2、使用time.time()方法计算

importtimestart=time.time()#中间写上代码块end=time.time()print('Runningtime:%sSeconds'%(end-start))

3、使用datetime.datetime.now()方法获取

importdatetimestart=datetime.datetime.now()#中间写代码块end=datetime.datetime.now()print('Runningtime:%sSeconds'%(end-start))

关于python获取程序执行时间的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。