转载自:blog

方法1

import datetime
starttime = datetime.datetime.now()
#long running
endtime = datetime.datetime.now()
print (endtime - starttime).seconds

方法 2

start = time.time()
run_fun()
end = time.time()
print end-start

方法3

start = time.clock()
run_fun()
end = time.clock()
print end-start