Benchmark a function over multiple iterations
(fn: Callable, iterations: int, **kwargs)
| 19 | from typing import Dict, Any, Callable |
| 20 | |
| 21 | def benchmark(fn: Callable, iterations: int, **kwargs) -> float: |
| 22 | """Benchmark a function over multiple iterations""" |
| 23 | start = time.perf_counter() |
| 24 | for _ in range(iterations): |
| 25 | fn(**kwargs) |
| 26 | end = time.perf_counter() |
| 27 | return (end - start) * 1000 # Convert to milliseconds |
| 28 | |
| 29 | def is_verbose() -> bool: |
| 30 | return ('--verbose' in sys.argv) or ('-v' in sys.argv) or (os.getenv('BENCH_VERBOSE') == '1') |
no test coverage detected