方法1
import datetime
import time
starttime = datetime.datetime.now()
#long running
time.sleep(2)
endtime = datetime.datetime.now()
str="run time: %d seconds" % ((endtime - starttime).seconds)
print(str)
方法2
import datetime
import time
start = time.time()
time.sleep(2)
end = time.time()
str="run time: %d seconds" % ( end-start)
print(str)
方法3
import datetime
import time
start = time.clock()
time.sleep(2)
end = time.clock()
str="run time: %d seconds" % ( end-start)
print(str)