运行效率问题
import time
def performance(unit):
def performance_decortor(f):
def wrapper(*args, **kw):
t1 = time.time()
r = f(*args, **kw)
t2 = time.time()
print 'call %s() in %f%s'%(f.__name__,(t2 - t1)*1000,unit)
return r
return wrapper
return performance_decortor
@performance('ms')
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
我这样写的代码,然后跟标准的都运行了,时间差距极大,运行了很多遍都是这样,试过换顺序,结果一直是上面运行时间比下面时间长,大概500倍左右,想知道为什么