bench
A Python benchmarking framework and command-line tool: bench run
for ad-hoc shell commands, and Python API for repeatable suites.
Quick start
As a CLI
$ bench run --runs 5 'sleep 0.01' 'sleep 0.02'
run (elapsed)
matrix mean ± σ min … max
sleep 0.01 11.03 ± 0.36 ms (10.66 … 11.49) (5 runs)
sleep 0.02 20.76 ± 0.16 ms (20.58 … 20.99) (5 runs)
Comparison - run (elapsed)
sleep 0.01 was
1.91 ± 0.07× better than sleep 0.02 (5 runs)
As a script
# compare.py
from bench import Time, bench, run, suite
s = suite(
"sleep",
bench("sleep")
.with_matrix(seconds=["0.01", "0.02"])
.with_command(lambda ctx: ["sleep", ctx.data.seconds])
.with_metric(Time())
.with_runs(5),
)
if __name__ == "__main__":
run(s)
$ python compare.py --json out.json
$ python compare.py show out.json
See examples/ for one runnable script per capability.
How it works
A suite holds benchmarks or other sub-suites.
Settings set on an app, suite or benchmark are inherited downwards.
Each benchmark expands into one variant per point of
its matrix (.with_matrix(**dims)), and each variant is run until its stopping
policy is satisfied (typically fixed number of runs).
Every run is an Execution in a Report.
Benchmarks run with an empty environment unless .with_env(...) or
.with_inherit_env() is used.
Variants can be dropped with .add_matrix_skip(...) or .with_filter(...),
runs spaced with .with_cooldown(s), and a suite's order randomized with
.with_shuffle(seed).
| Component | Setter | |
|---|---|---|
| Metric | .with_metric(...) |
Turns a finished run into samples |
| Stopping policy | .with_runs(...), |
Decides when a variant has run enough times |
.with_warmup(...) |
Same as runs, but marks runs as warmups | |
| Runner | .with_runner(...) |
Schedules variants: sequential, parallel or dry |
| Reporter | .with_reporter(...) |
Shows progress reports to setup output (JSON, CSV, ...) |
| Summary | .with_summary(...) |
Renders statistics after the run |
| Hooks | .with_hook(...) |
Runs setup/teardown code around each execution |
| Outlier detection | .with_outlier_detection(...) |
Flags outlying samples |
Outputs: live progress, the summary, and optionally --json, --csv and
--dir. bench show report.json re-renders a saved report.
bench compare a.json b.json ... compares saved reports, the first being the baseline.
Noise: bench doctor prints the machine fingerprint and flags noise
sources, exiting non-zero on a high-severity one. On Linux as root, bench denoise minimize|restore|status quiets those knobs and reverts them.
bench run --check-environment / --denoise do the same around a run;
scripts use bench_app(probe=SystemProbe(), denoise=True).
Development
The linter, typechecker, formatter and tests all run uppon running
make check
To format the project use
make format
To fix auto-fixable Ruff errors use
make fix-lint
Acknowledgements
Much of the bench has been inspired by these great tools:
- hyperfine - CLI ergonomics and comparison output
- ReBench - configuration-driven design and the built-in
RebenchMetric
License
Metadata
Release files for bench-framework 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bench_framework-0.1.0.tar.gz | 191.9 kB | Without provenance | Details for bench_framework-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bench_framework-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for bench_framework-0.1.0-py3-none-any.whl |
Total release size: 288.8 kB
Release files / bench_framework-0.1.0.tar.gz
| Download URL | bench_framework-0.1.0.tar.gz |
|---|---|
| Size | 191.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac62db53a393a7adbf151380c0ca0516d95b84f3205b8d5de56bb4b5ec724f51
|
|
BLAKE2b-256 checksum How to use checksums |
8e01ccaa486350387990be16a515e1bda873a35bc7df26b53f566d9d3768235b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / bench_framework-0.1.0-py3-none-any.whl
| Download URL | bench_framework-0.1.0-py3-none-any.whl |
|---|---|
| Size | 96.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b1ae2331995e6bcdd5391011258092ee20cbf682557fa6cf13bfa7a4777afbe5
|
|
BLAKE2b-256 checksum How to use checksums |
29784c85ef996aa4c0973d4dee0bf2d57898b00811f1875d9c0535e15b174ef1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for bench-framework 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.