python 程序运行时间

1.在起始处添加 开始时间

2.程序运行

3.末尾处添加结束时间

4.结束时间 减去开始时间

 1 start1 = time.process_time()
 2 start2 = time.time()
 3 start3 = datetime.datetime.now()
 4 
 5 
 6 end1 = time.process_time()
 7 end2 = time.time()
 8 end3 = datetime.datetime.now()
 9 
10 print("程序运行时间1:",end1-start1)
11 print("程序运行时间2:",end2-start2)
12 print ("程序运行时间3:",(end3 - start3).seconds)

结果:

原文地址:https://www.cnblogs.com/whycai/p/14310818.html