Skip to main content

larzbench

Ergonomic micro-benchmarking. Pure Python, zero dependencies.

timeit works, but it's awkward - stringy, one number. larzbench measures a callable across several rounds, auto-calibrates the iteration count, and gives you real statistics plus a one-call compare() that ranks several implementations.

from larzbench import benchmark, compare

r = benchmark(lambda: sum(range(1000)))
print(r)      # <lambda>: best 8.10us  mean 8.44us  118,000 ops/s

compare({
    "listcomp": lambda: [x*x for x in range(1000)],
    "map":      lambda: list(map(lambda x: x*x, range(1000))),
}).report()
# listcomp   42.10us/op  23,753 ops/s  (fastest)
# map        61.30us/op  16,313 ops/s  1.46x slower

Why

  • Real stats, not one number. best / mean / median / stdev and ops-per-second, over multiple rounds with a warmup - so noise and cold caches don't fool you.
  • Auto-calibration. It picks an iteration count that runs long enough to be meaningful, so you don't guess.
  • compare() is the killer feature. Pass a dict of implementations; get them ranked fastest-first with relative slowdowns and a printable report.
  • Testable. Pass a clock to make timings deterministic (this repo's tests do exactly that).
  • Zero dependencies.

Install

pip install larzbench

Usage

from larzbench import benchmark, compare

benchmark(func, *args, rounds=5, iterations=None, warmup=True, name=None, **kwargs)
# -> Result: .best .mean .median .stdev .ops_per_sec .per_op

compare({"a": fn_a, "b": fn_b}, rounds=7).report()

Tests

python -m unittest discover -s tests -v   # 7 tests (deterministic via a fake clock)

The Larz stack

One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.

License

MIT (c) larz-scripter

Metadata

Release files for larzbench 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for larzbench 0.1.0
File Size Uploaded Provenance
larzbench-0.1.0.tar.gz 5.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for larzbench 0.1.0
File Interpreter ABI Platform
larzbench-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.7 kB

Release files / larzbench-0.1.0.tar.gz

Download URL larzbench-0.1.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b88ced150658d49e9b63fcb00b78e410f70242d7a332b79bfc6d689aef29c468
BLAKE2b-256 checksum
How to use checksums
37886676165d72d66e258f817a0dda714eb4311eb7ffe88a767229625812ac7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / larzbench-0.1.0-py3-none-any.whl

Download URL larzbench-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd2685a9fa8c156777bce09ff9d8ef326680b68696af82bd1da8134958682be6
BLAKE2b-256 checksum
How to use checksums
ccc08b1fa561b60cda2912c60ef89b51e5d5bc7ff442476e3481256051c14b25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for larzbench 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page