#有多个函数,需要计算他们的执行时间
import time
def show_time(f):
def inner(*x,**y):
starttime = time.time()
f(*x,**y)
endtime = time.time()
print("执行时间:%s"%(endtime - starttime))
return inner
@show_time #foo = show_time(foo) @show_time同等与foo = show_time(foo)
def foo(*a,**b):
fnum = 0
for i in a:
fnum += i
print(fnum)
print("this is foo")
time.sleep(2)
#foo = show_time(foo)
foo(1,2,3,4,5,6)
原文:https://www.cnblogs.com/TKOPython/p/11734539.html