美文网首页
python 计时器装饰器

python 计时器装饰器

作者: SkTj | 来源:发表于2019-12-04 11:06 被阅读0次

import time
from functools import wraps

def timethis(func):
'''
Decorator that reports the execution time.
'''
@wraps(func)
def wrapper(*args, *kwargs):
start = time.time()
result = func(
args, **kwargs)
end = time.time()
print(func.name, end-start)
return result
return wrapper

解除装饰器

@somedecorator
def add(x, y):
... return x + y
...
orig_add = add.wrapped
orig_add(3, 4)
7

相关文章

网友评论

      本文标题:python 计时器装饰器

      本文链接:https://www.haomeiwen.com/subject/uhhhpctx.html