Quickstart¶
You’ll write one benchmark, run it, and inspect the result.
1. Create benchmarks/bench_sort.py¶
# benchmarks/bench_sort.py
import mew
@mew.benchmark
def bench_sorted(state: mew.State) -> None:
data = list(range(1000, 0, -1))
for _ in state:
sorted(data)
The contract is the same as Google Benchmark: do setup outside the
for _ in state: loop, do the measured work inside it. mew discovers
files matching bench_*.py or *_bench.py under benchmarks/ by default.
2. Run it¶
$ 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
3. Persist results¶
Direct output to a file with -o:
$ mew run -o results.json # JSON document
$ mew run -o results.parquet # one row per Run
$ mew run -o - -o results.json # fan out to stdout AND a file
4. Parametrize¶
When you want to benchmark parametric functions for many different inputs, decorate it with @mew.parametrize:
@mew.parametrize([{"n": 10}, {"n": 100}, {"n": 1000}])
def bench_sorted(state: mew.State, n: int) -> None:
data = list(range(n, 0, -1))
for _ in state:
sorted(data)
Or use a cartesian product for all possible parameter combinations:
@mew.product(n=[10, 100, 1000], algo=["timsort", "quick"])
def bench_sort(state: mew.State, n: int, algo: str) -> None:
...
See Parametrizations for full semantics.
Next steps¶
Concepts — how
mewthinks about benchmarks, families, and timings.CPU profiling — turn a slow benchmark into a flame graph.
Comparisons and regression gating — fail CI when a benchmark regresses by more than N %.