debug.py 文件源码

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

项目:nlp-playground 作者: jamesmishra 项目源码 文件源码
def easy_timer(code_to_benchmark, *, repeat=3, number=1000):
    """
    Wrap timeit.Timer().repeat() to catch locals.

    Rather than put our setup statement in a string for
    :py:func:`timeit.timeit`, we can just pull locals and globals
    from the calling stack frame.

    Args:
        code_to_benchmark(str): A string containing the Python code
            that we want to benchmark.

        repeat(int): Number of times to repeat the timer trial.

        number(int): Number of iterations **per** trial.

    Returns:
        (float): The best measured time of ``repeat`` times.

    """
    timer = timeit.Timer(stmt=code_to_benchmark, globals=copy_environment(2))
    best_time = min(timer.repeat(repeat=repeat, number=number))
    return best_time
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号