Python看程序执行时间(time模块)

Python看程序执行时间需要用到time模块,该模块提供了各种时间相关的函数。相关功能还可以参阅 datetime 和 calendar 模块。

time模块的官方文档https://docs.python.org/zh-cn/3.6/library/time.html#module-time

这个模块是用C写的,源码见https://github.com/python/cpython/blob/master/Modules/timemodule.c

一个查看程序运行时间的小例子

导入time模块:

import time

在程序开始执行的地方:

start=time.clock()

程序末尾:

end=time.clock()

打印运行时间:

print("final is in ",end-start)
发布了89 篇原创文章 · 获赞 68 · 访问量 32万+

猜你喜欢

转载自blog.csdn.net/symoriaty/article/details/102667560