Function
run_benchmark
(
func: Callable[..., Any],
args: Tuple[Any, ...],
*,
warmup: int,
iterations: int,
repeat: int,
number: int,
)
Source from the content-addressed store, hash-verified
| 745 | |
| 746 | |
| 747 | def run_benchmark( |
| 748 | func: Callable[..., Any], |
| 749 | args: Tuple[Any, ...], |
| 750 | *, |
| 751 | warmup: int, |
| 752 | iterations: int, |
| 753 | repeat: int, |
| 754 | number: int, |
| 755 | ) -> Tuple[float, float]: |
| 756 | for _ in range(warmup): |
| 757 | for _ in range(number): |
| 758 | func(*args) |
| 759 | |
| 760 | samples: List[float] = [] |
| 761 | for _ in range(iterations): |
| 762 | timer = timeit.Timer(lambda: func(*args)) |
| 763 | loop_times = timer.repeat(repeat=repeat, number=number) |
| 764 | samples.extend([time_total / number for time_total in loop_times]) |
| 765 | |
| 766 | mean = statistics.mean(samples) |
| 767 | stdev = statistics.stdev(samples) if len(samples) > 1 else 0.0 |
| 768 | return mean, stdev |
| 769 | |
| 770 | |
| 771 | def format_time(seconds: float) -> str: |
Tested by
no test coverage detected