utils.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:yadll 作者: pchavanne 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号