pybench:
What is it?
pybench is a simple benchmarking framework that mimics pytest syntax. Simply write create files beginning with "bench_" and pybench will discover those files and benchmark all functions starting with "bench_". Internally, pybench relies on Python's standard timeit library to produce benchmark statistics. These statistics, along with metadata such as your platform, available CPUs, RAM, project version, commit id, and more, are stored in a parquet file for further analysis. That way, you have access to the raw data necessary to track performance over time and commits, identify regressions, and any other analysis you may want to do.
Usage:
Dependencies
- polars
- toml
- tqdm
Installing
The easiest way is to install cli-pybench is from PyPI using pip:
pip install cli-pybench
Quickstart
Installing the library will expose a pybench command in your terminal. Although the benchmark directory is configurable, by convention, create a folder called "benchmarks" in your project root. Then, create a file prefixed with "bench_". In that file, write a function starting with "bench_".
def bench_my_sum():
1 + 1
Then, simply run pybench from your terminal! It should look something like this:
starting benchmark session ...
default config: Config(benchpath='benchmarks', repeat=30, number=1, warmups=0, garbage_collection=False)
running on Linux-5.15.123.1-microsoft-standard-WSL2-x86_64-with-glibc2.35 with x86_64, available cpus: 16, RAM: 10.05GB
/home/cangyuanli/Documents/Projects/cli-pybench/benchmarks/bench_pybench.py
100%|██████████████████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:00<00:00, 184.31it/s]
Then, a "results.parquet" file representing your most recent run will appear in your "benchmarks/results" folder. In addition, a Hive-partitioned folder will be created (by default partitioned by commit) in "benchmarks/results/historical". If you want to change your configuration, you can do it globally through your "pyproject.toml" file like so:
[tool.pybench]
repeat = 100
number = 10
warmups = 1
To learn more about the repeat and number parameters, see the documentation for timeit.repeat here: https://docs.python.org/3/library/timeit.html.
You can also change your configuration for a specific function through the pybench.config decorator. Here's an example:
import pybench
@pybench.config(repeat=1_000, number=100)
def bench_my_sum():
1 + 1
pybench provides three other decorators. One is the pybench.skipif decorator. It simply skips the function if the input evaluates to True. This is useful for a variety of reasons, for example, if you have a long-running benchmark that you do not want to run frequently. of course, all decorators can be combined.
import pybench
@pybench.config(repeat=1_000, number=100)
@pybench.skipif(True)
def bench_my_sum():
1 + 1
Another is pybench.metadata. This attaches arbitrary per-function metadata.
import pybench
@pybench.metadata(group="add")
def bench_my_sum():
1 + 1
@pybench.metadata(group="add")
def bench_other_sum():
1 + 1
The final decorator is the pybench.parametrize decorator. This benchmarks your function for each input in a given list of inputs. There are two syntaxes for this. The first is the dictionary syntax.
import pybench
@pybench.parametrize({"a": [1, 2], "b": [5, 8, 9]})
def bench_my_sum(a, b):
a + b
This will benchmark bench_my_sum for the product of "a" and "b", i.e. every pair of "a" and "b". Users of pytest may be more familiar with the second syntax.
import pybench
@pybench.parametrize(("a", "b"), [(1, 2), (3, 4)])
def bench_my_sum(a, b):
a + b
Metadata
Release files for cli-pybench 0.1.2
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 | |
|---|---|---|---|---|
| cli_pybench-0.1.2.tar.gz | 9.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cli_pybench-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.5 kB
Release files / cli_pybench-0.1.2.tar.gz
| Download URL | cli_pybench-0.1.2.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc185fccbe2752f81bf1ab48f43a0a3f4defd94a48b67332ab377c175781aedd
|
|
BLAKE2b-256 checksum How to use checksums |
1417506a68c9e1262432ddfa9f3efd53dddbe7de088666741be323bf842845df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / cli_pybench-0.1.2-py3-none-any.whl
| Download URL | cli_pybench-0.1.2-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df374da5fd39a550bb37499cfe5a6b04d19172ae143bcffdef761fb0e2204a9a
|
|
BLAKE2b-256 checksum How to use checksums |
3e853b6349630512e6ac12557734601525ac9e2711714604549bbbc525990c8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for cli-pybench 0.1.2
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.