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, 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 @ 3200MHz scaling=enabled
Benchmark │ Iters │ Real │ CPU
─────────────────────────────────────────────────────────────────────────────────────
benchmarks/bench_sort.py::bench_sorted │ 1,000,000 │ 32.10 ns │ 32.05 ns
At a glance¶
@mew.benchmark, @mew.parametrize, @mew.product — register one
benchmark or a family.
mew run discovers bench_*.py files, runs them with Google Benchmark, and
streams results to the terminal, JSON, or Parquet.
--sample for pyinstrument CPU sampling, --profile-memory for memray
allocations, or mew profile for native C frames via Instruments / py-spy / perf.
mew compare baseline.json head.json --fail-on-regression 5 for CI
regression gates with an allowlist.
Table of Contents¶
Getting started
User guide
Reference
Development