Zero-overhead Python Benchmarking
zerobench is a Python benchmarking library with zero overhead, designed for multidimensional performance analysis.
Features
- Context manager API: Benchmark any code block with
with bench(...): ... - Multidimensional: Tag benchmarks with arbitrary keyword arguments
- Zero overhead: Code is passed directly to
timeit.Timer, no wrapper function - Auto-scaling: Automatically determines the number of iterations for reliable measurements
- Multiple exports: CSV, Parquet, Markdown
- Plotting: Built-in visualization with matplotlib
Quick Example
from zerobench import Benchmark
bench = Benchmark()
for n in [100, 1000, 10000]:
data = list(range(n))
with bench(method='sum', n=n):
sum(data)
with bench(method='len', n=n):
len(data)
Output:
method=sum, n=100: 0.579 us ± 2.38 ns (median ± std. dev. of 7 runs, 500000 loops each)
method=len, n=100: 0.020 us ± 0.45 ns (median ± std. dev. of 7 runs, 20000000 loops each)
method=sum, n=1000: 5.369 us ± 44.70 ns (median ± std. dev. of 7 runs, 50000 loops each)
method=len, n=1000: 0.029 us ± 0.09 ns (median ± std. dev. of 7 runs, 10000000 loops each)
method=sum, n=10000: 53.728 us ± 69.86 ns (median ± std. dev. of 7 runs, 5000 loops each)
method=len, n=10000: 0.029 us ± 0.25 ns (median ± std. dev. of 7 runs, 10000000 loops each)
print(bench)
┌────────┬────────┬─────────────────────────────────┐
│ method ┆ n ┆ execution_times │
╞════════╪════════╪═════════════════════════════════╡
│ sum ┆ 100 ┆ [0.577805, 0.57815, … 0.581231… │
│ len ┆ 100 ┆ [0.019207, 0.019278, … 0.01958… │
│ sum ┆ 1_000 ┆ [5.417795, 5.33863, … 5.35146] │
│ len ┆ 1_000 ┆ [0.028898, 0.030144, … 0.03007… │
│ sum ┆ 10_000 ┆ [53.743199, 53.664567, … 53.72… │
│ len ┆ 10_000 ┆ [0.028857, 0.028911, … 0.02942… │
└────────┴────────┴─────────────────────────────────┘
JAX Support
ZeroBench automatically detects JAX arrays and optimizes benchmarking accordingly:
import jax.numpy as jnp
from zerobench import Benchmark
bench = Benchmark()
x = jnp.ones(1000)
y = jnp.ones(1000)
with bench(method='add'):
x + y
When JAX code is detected, zerobench:
- Wraps the code in a JIT-compiled function to measure optimized execution
- Separates compilation from execution by reporting
compilation_timeseparately - Captures the StableHLO representation of the compiled function in the
hlofield - Uses
jax.block_until_readyto ensure accurate timing of asynchronous operations
The benchmark report includes additional fields for JAX:
first_execution_time: Time of the initial (possibly uncompiled) executioncompilation_time: Time to lower and compile the functionhlo: The StableHLO text representation of the compiled computation
report = bench.to_dicts()[0]
print(report['compilation_time']) # e.g., 12345.67 ns
print(report['hlo'][:100]) # HLO module "jit___bench_func" ...
Installation
pip install zerobench
Export and Visualization
# Export results
bench.write_csv('results.csv')
bench.write_parquet('results.parquet')
bench.write_markdown('results.md')
# Plot results
bench.plot()
bench.write_plot('results.pdf')
Configuration
Benchmark(
repeat=7, # Number of measurement repetitions
min_duration_of_repeat=0.2, # Minimum duration per repeat (seconds)
time_units='ns', # Time units: 'ns', 'us', 'ms', 's'
)
License
MIT
Metadata
Release files for zerobench 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| zerobench-0.5.tar.gz | 217.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zerobench-0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 230.4 kB
Release files / zerobench-0.5.tar.gz
| Download URL | zerobench-0.5.tar.gz |
|---|---|
| Size | 217.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68990f51ad7269237145a23f145221bda9e4985ab8d900209c8798f5b65493bc
|
|
BLAKE2b-256 checksum How to use checksums |
62ed708d02d5b7fbad4e7d67f4a7b242e557c8372e2bbc68630955c2b104d383
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 4, 2026.
Transparency logRelease files / zerobench-0.5-py3-none-any.whl
| Download URL | zerobench-0.5-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d65fd802927c1ebd63fd2861499077cef0a8136c0df6d111eb5bab30927e9d81
|
|
BLAKE2b-256 checksum How to use checksums |
1f33f11d6f86b977ed7238978477df43a030977583125e65b2ab362271794b7c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 4, 2026.
Transparency log