Introduction¶
Simple microbenchmarking of Python snippets, powered by Google Benchmark.
mew is a small Python library and CLI for writing microbenchmarks the way you
write tests: decorate a function, run mew, get reliable timings, backed by
Google Benchmark and built with nanobind.
import mew
@mew.benchmark
def bench_sorted(state: mew.State) -> None:
data = list(range(1000, 0, -1))
for _ in state:
sorted(data)
$ mew run
mew · host=laptop cpus=10 scaling=enabled
Benchmark │ Iters │ Real │ CPU
─────────────────────────────────────────────────────────────────────────────────────
benchmarks/bench_sort.py::bench_sorted │ 1,000,000 │ 32.10 ns │ 32.05 ns
At a glance¶
Register one benchmark or a family with @mew.benchmark,
@mew.parametrize, or @mew.product.
mew run discovers bench_*.py files, runs them with Google Benchmark, and
streams results to the terminal, JSON, or a JSONL archive.
--sample for pyinstrument CPU sampling, --profile-memory for memray
allocations. For native C frames, sample the process from outside (see the native-profiling recipe).
mew compare head.json baseline.json --regression-threshold 5% --exit-non-zero-on-regression for CI
regression gates with an allowlist.
Table of Contents¶
Getting started
User guide
Reference
Development