Python--装饰器
import time
#import funct # define decorator# record time1 #call f and excute f then store the result in 'r'
# reocond end time
#compute time2-time1
##return result
#return decorator
def performance(f):
def fn(*args):
t1=time.time()
r=f(*args)
t2=time.time()
print f.__name__+ ' '+str(t2-t1)
return r
return fn
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)