Python有三种方法来查看程序运行时间
方法1
import datetime
start = datetime.datetime.now()
run_function(): # do something
end = datetime.datetime.now()
print(str(end-start))
方法2
import time
start = time.time()
run_function()
end = time.time()
print(str(end))
方法3
start = time.clock()
run_function()
end = time.clock()
print(str(end-start))
网友评论