【Python程序计时】使用time模块实现计时功能
在Python中经常需要对程序运行时间进行掌控,一般使用time模块进行计时:
import time
start = time.perf_counter()
######## 实际程序开始 ##########
for i in range(10000):
for j in range(10000):
pass
######## 实际程序结束 ##########
end = time.perf_counter()
print("运行时间为", round(end-start), 'seconds')
测试结果如下:
运行时间为 4 seconds