ch08, 09, 10: example files
This commit is contained in:
13
09-closure-deco/clockdeco0.py
Normal file
13
09-closure-deco/clockdeco0.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import time
|
||||
|
||||
|
||||
def clock(func):
|
||||
def clocked(*args): # <1>
|
||||
t0 = time.perf_counter()
|
||||
result = func(*args) # <2>
|
||||
elapsed = time.perf_counter() - t0
|
||||
name = func.__name__
|
||||
arg_str = ', '.join(repr(arg) for arg in args)
|
||||
print(f'[{elapsed:0.8f}s] {name}({arg_str}) -> {result!r}')
|
||||
return result
|
||||
return clocked # <3>
|
||||
Reference in New Issue
Block a user