时间问题。。。运行时间算出来是0,被装饰过的函数变成了int型()Python 3.x
import time
from _functools import reduce
def factorial_decorator(str_func_args):
def decorator(factorial):
def warpper(*args, **kw):
startTime = time.time()
funced = factorial(*args, **kw)
finishTime = time.time()
if str_func_args == 'ms':
atime = (finishTime - startTime) * 1000
else:
atime = (finishTime - startTime)
print('call in %f%s' % ( atime , str_func_args))
print(type(funced))
return funced
return warpper
return decorator
@factorial_decorator('ms')
def factorial(n):
return reduce(lambda x,y: x*y, range(1,n+1))
print(factorial(10))
结果:
call in 0.000000ms
<class 'int'>
3628800