16 lines
359 B
Python
16 lines
359 B
Python
# clockdeco.py
|
|
|
|
import time
|
|
|
|
|
|
def clock(func):
|
|
def clocked(*args):
|
|
t0 = time.time()
|
|
result = func(*args)
|
|
elapsed = time.time() - t0
|
|
name = func.__name__
|
|
arg_str = ', '.join(repr(arg) for arg in args)
|
|
print('[%0.8fs] %s(%s) -> %r' % (elapsed, name, arg_str, result))
|
|
return result
|
|
return clocked
|