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
评论列表
文章目录