A multidimensional benchmarking library with minimal overhead
Project description
Zero-overhead Python and JAX Reliable Benchmarking
ZeroPyBench 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 zeropybench 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: 575.124 ns ± 3.35% (median of 7 runs, 500000 loops each)
method=len, n=100: 19.037 ns ± 0.85% (median of 7 runs, 20000000 loops each)
method=sum, n=1000: 2.961 µs ± 36.70% (median of 7 runs, 50000 loops each)
method=len, n=1000: 19.844 ns ± 38.63% (median of 7 runs, 10000000 loops each)
method=sum, n=10000: 50.208 µs ± 9.89% (median of 7 runs, 5000 loops each)
method=len, n=10000: 28.686 ns ± 1.22% (median of 7 runs, 20000000 loops each)
print(bench)
┌───┬────────┬────────┬────────────────────────────┬───────────┐
│ ┆ method ┆ n ┆ median_execution_time (ns) ┆ ± (%) │
╞═══╪════════╪════════╪════════════════════════════╪═══════════╡
│ 0 ┆ sum ┆ 100 ┆ 575.124442 ┆ 3.353129 │
│ 1 ┆ len ┆ 100 ┆ 19.036998 ┆ 0.854601 │
│ 2 ┆ sum ┆ 1_000 ┆ 2_961.25732 ┆ 36.698258 │
│ 3 ┆ len ┆ 1_000 ┆ 19.844193 ┆ 38.63371 │
│ 4 ┆ sum ┆ 10_000 ┆ 50_207.584997 ┆ 9.894165 │
│ 5 ┆ len ┆ 10_000 ┆ 28.686439 ┆ 1.22376 │
└───┴────────┴────────┴────────────────────────────┴───────────┘
JAX Support
ZeroPyBench automatically detects JAX arrays and optimizes benchmarking accordingly:
import jax.numpy as jnp
from zeropybench import Benchmark
bench = Benchmark(repeat=20, verbose=True)
x = jnp.ones(1_000_000)
y = jnp.ones(1_000_000)
with bench():
x + y
Setup code:
@jax.jit
def __bench_func(x, y):
return x + y
Benchmarked code:
__bench_func(x, y).block_until_ready()
943.426 µs ± 3.98% (median of 20 runs, 500 loops each)
When JAX code is detected, ZeroPyBench:
- 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
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[0]
print(report['compilation_time']) # e.g., 12345.67 ns
print(report['hlo'][:100]) # HLO module "jit___bench_func" ...
Installation
pip install zeropybench
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_per_repeat=0.2, # Minimum duration per repeat (seconds)
verbose=True, # Print the setup and benchmarked code
)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zeropybench-1.1.0.tar.gz.
File metadata
- Download URL: zeropybench-1.1.0.tar.gz
- Upload date:
- Size: 240.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
532cd4cbd7198944defb7c83ec9642139712e188c984ad104c4c4eceabf6e60d
|
|
| MD5 |
5e6b471df4991baa1e060ae40c892bb0
|
|
| BLAKE2b-256 |
f18d296fefe32005fdb0f9e6edec80c825ce7ee730284650465d5cbddb392a35
|
Provenance
The following attestation bundles were made for zeropybench-1.1.0.tar.gz:
Publisher:
release.yml on CMBSciPol/zeropybench
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zeropybench-1.1.0.tar.gz -
Subject digest:
532cd4cbd7198944defb7c83ec9642139712e188c984ad104c4c4eceabf6e60d - Sigstore transparency entry: 1198485139
- Sigstore integration time:
-
Permalink:
CMBSciPol/zeropybench@7580e92feb653976f515414a46a8f71a699d3e6c -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/CMBSciPol
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7580e92feb653976f515414a46a8f71a699d3e6c -
Trigger Event:
release
-
Statement type:
File details
Details for the file zeropybench-1.1.0-py3-none-any.whl.
File metadata
- Download URL: zeropybench-1.1.0-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8569dfe2aa16cb5963fc4fa117f31f0b78bbde16be24da0495819baa636886eb
|
|
| MD5 |
5715da70029f63d32718cdd66afc016d
|
|
| BLAKE2b-256 |
30f51fb59a0b89ba844f5ec6bb9b273f6d1eec98d8ae1321dd6f57375b854039
|
Provenance
The following attestation bundles were made for zeropybench-1.1.0-py3-none-any.whl:
Publisher:
release.yml on CMBSciPol/zeropybench
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zeropybench-1.1.0-py3-none-any.whl -
Subject digest:
8569dfe2aa16cb5963fc4fa117f31f0b78bbde16be24da0495819baa636886eb - Sigstore transparency entry: 1198485144
- Sigstore integration time:
-
Permalink:
CMBSciPol/zeropybench@7580e92feb653976f515414a46a8f71a699d3e6c -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/CMBSciPol
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7580e92feb653976f515414a46a8f71a699d3e6c -
Trigger Event:
release
-
Statement type: