import time, functools
def metric(fn):
t = time.perf_counter()
@functools.wraps(fn)#保证在修饰后fn.__name__不发生变化
def decorator(*args,**kw):
k=fn(*args,**kw)
print('%s executed in %s ms' % (fn.__name__, time.perf_counter()-t))
return k
return decorator
Sign in to make a reply
Haley要fighting
import time, functools
def metric(fn):
t = time.perf_counter()
@functools.wraps(fn)#保证在修饰后fn.__name__不发生变化
def decorator(*args,**kw):
k=fn(*args,**kw)
print('%s executed in %s ms' % (fn.__name__, time.perf_counter()-t))
return k
return decorator