#-*-coding:UTF-8-*-importtimedeffoo():print('infoo()')deftimeit(func):#定义一个内嵌的包装函数,给传入的函数加上计时功能的包装defwrapper():start=time.clock()func()end=time.clock()print('used:',end-start)#将包装后的函数返回returnwrapper@timeitdeffoo2():print("infoo2")foo=timeit(foo)foo()print("_*_"*20)foo3=timeit(foo2)foo3()print("_*_"*20)foo2()结果:infoo()used:0.00016424599357094254_*__*__*__*__*__*__*__*__*__*__*__*__*__*__*__*__*__*__*__*_infoo2used:2.4441368090914078e-05used:0.0005895257983528473_*__*__*__*__*__*__*__*__*__*__*__*__*__*__*__*__*__*__*__*_infoo2used:2.7863159623642037e-05[Finishedin15.0s]请说明为什么调用foo3会出现两次used?
添加回答
举报
0/150
提交
取消