forked from kosipov/pp_122-mko-lab2
14 lines
556 B
Python
14 lines
556 B
Python
import statistics
|
||
import time
|
||
|
||
def bench(func, *args, repeats=5, warmup=1):
|
||
"""Возвращает медиану, минимум и максимум времени func(*args), с."""
|
||
for _ in range(warmup): # прогрев: кэши, JIT
|
||
func(*args)
|
||
times = []
|
||
for _ in range(repeats):
|
||
start = time.perf_counter() # монотонный таймер высокого разрешения
|
||
func(*args)
|
||
times.append(time.perf_counter() - start)
|
||
return statistics.median(times), min(times), max(times)
|