python 记录运行时间的方法
- 第一种
import time start = time.clock() print(start) sum = 0 for i in range(1000000): sum +=i end = time.clock() print(end) yongshi = end - start print("总耗时为:%s" % yongshi) time.clock()#此方法在python 3.3中将被弃用,python3.8 中将删除use time
- 第二种
import time start = time.time() sum = 0 for i in range(1000000): sum +=i time.sleep(2) end = time.time() yongshi = end - start print("总耗时为:%s" % yongshi)
- 第三种
import datetime starttime = datetime.datetime.now() print(starttime) sum = 0 for i in range(100000000): sum += i #long running endtime = datetime.datetime.now() print(endtime) print(endtime - starttime)
本文来自博客园,作者:手可摘星辰/*,转载请注明原文链接:https://www.cnblogs.com/u-damowang1/p/12159053.html