Getting started¶
Requirements¶
- Python 3.12 or newer
- No required runtime dependencies
Install the core package:
pip install benchcore
Install the optional pytest dependency:
pip install "benchcore[pytest]"
Run a configured benchmark¶
from benchcore.core.models import BenchmarkConfig
from benchcore import Bench
bench = Bench(
BenchmarkConfig(
rounds=10,
warmup_rounds=2,
)
)
result = bench.run(sorted, [5, 4, 3, 2, 1])
print(result.value)
print(result.iterations)
print(result.statistics.mean_ns)
Automatic calibration is enabled when iterations is None. Set a positive
integer to reproduce a fixed workload:
config = BenchmarkConfig(rounds=20, iterations=100, warmup_rounds=3)
Create and render a report¶
from benchcore.reporting import TerminalReporter, create_report
report = create_report("sorted-small", result)
print(TerminalReporter().render(report))
Reporting happens after measurement and never inside the timed region.