updated from Atlas
This commit is contained in:
17
09-closure-deco/clock/clockdeco.py
Normal file
17
09-closure-deco/clock/clockdeco.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import time
|
||||
import functools
|
||||
|
||||
|
||||
def clock(func):
|
||||
@functools.wraps(func)
|
||||
def clocked(*args, **kwargs):
|
||||
t0 = time.perf_counter()
|
||||
result = func(*args, **kwargs)
|
||||
elapsed = time.perf_counter() - t0
|
||||
name = func.__name__
|
||||
arg_lst = [repr(arg) for arg in args]
|
||||
arg_lst.extend(f'{k}={v!r}' for k, v in kwargs.items())
|
||||
arg_str = ', '.join(arg_lst)
|
||||
print(f'[{elapsed:0.8f}s] {name}({arg_str}) -> {result!r}')
|
||||
return result
|
||||
return clocked
|
||||
Reference in New Issue
Block a user