python 中显示程序运行时间的方法

显示程序运行时间的方法

首先导入时间模块

import time

在程序开头写

start_time = time.clock()

在程序结尾写

end_time = time.clock()

最后输出时间计算结果

print("final is in ",end_time - start_time)

!!!在 python 3.8 中以上写法是出错的,报错如下:

DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead

time.clock 在 python3.3 已经别移除了,需要用 time.perf_counter 或 time.process_time 来代替

转载:

Python3.7中time模块的time()、perf_counter()和process_time()的区别
https://blog.csdn.net/qq_27283619/article/details/89280974

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容