def timer(what_to_show="Function execution"):
"""
decorator that send the execution time of the argument function to the logger
Parameters
----------
what_to_show : `string`, optional
message displayed after execution
"""
def func_wrapper(func):
@wraps(func)
def wrapper(*args, **kwargs):
start_time = timeit.default_timer()
res = func(*args, **kwargs)
end_time = timeit.default_timer()
s = end_time - start_time
try:
msg = what_to_show + ' ' + args[0].name
except (AttributeError, IndexError, TypeError):
msg = what_to_show
logger.info('%s took %s' % (msg, format_sec(s)))
return res
return wrapper
return func_wrapper
评论列表
文章目录