python 计时器装饰器

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 计时器装饰器)