updated from Atlas
This commit is contained in:
23
attic/decorators/clockdeco2.py
Normal file
23
attic/decorators/clockdeco2.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# clockdeco2.py
|
||||
|
||||
import time
|
||||
import functools
|
||||
|
||||
|
||||
def clock(func):
|
||||
@functools.wraps(func)
|
||||
def clocked(*args, **kwargs):
|
||||
t0 = time.time()
|
||||
result = func(*args, **kwargs)
|
||||
elapsed = time.time() - t0
|
||||
name = func.__name__
|
||||
arg_lst = []
|
||||
if args:
|
||||
arg_lst.append(', '.join(repr(arg) for arg in args))
|
||||
if kwargs:
|
||||
pairs = ['%s=%r' % (k, w) for k, w in sorted(kwargs.items())]
|
||||
arg_lst.append(', '.join(pairs))
|
||||
arg_str = ', '.join(arg_lst)
|
||||
print('[%0.8fs] %s(%s) -> %r ' % (elapsed, name, arg_str, result))
|
||||
return result
|
||||
return clocked
|
||||
Reference in New Issue
Block a user