python record running time method

  • The first
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 ( " total time was:% S " % Yongshi) 
time.clock () # this method will be deprecated in a python 3.3, python3.8 use time will delete
  • The second
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)
  • The third
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)

Guess you like

Origin www.cnblogs.com/u-damowang1/p/12159053.html
Recommended