def print_easy_timer(code_to_benchmark, *, repeat=3, number=1000):
"""
Repeatedly time code and print results.
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))
print(":\t\t".join((
code_to_benchmark,
str(best_time)
)))
return best_time
评论列表
文章目录