import time
import functools
def performance(f):
def timeit(x):
start = time.clock()
f(x)
end = time.clock()
return end - start
return timeit
@performance
def factorial(n):
return functools.reduce(lambda x, y: x * y, range(1, n+1))
print(factorial(10))
1 回答
精慕门闇黑龙帝
TA贡献3条经验 获得超0个赞
import time import functools def performance(f): def timeit(x): start = time.clock() end = time.clock() print('Used: ', end - start) return f(x) return timeit @performance def factorial(n): return functools.reduce(lambda x, y: x * y, range(1, n+1)) print(factorial(10))
只能通过单独在timeit()函数内用print()输出时间......
添加回答
举报
0/150
提交
取消