Parametrizations

Two decorators register benchmark families — one body, many variants.

@mew.parametrize

Takes an iterable of keyword argument dicts. One variant per dict is registered:

@mew.parametrize([
    {"n": 10, "algo": "merge"},
    {"n": 100, "algo": "quick"},
], min_time=0.05, tags="sort")
def bench_sort(state: mew.State, n: int, algo: str) -> None:
    data = list(range(n, 0, -1))
    for _ in state:
        sorted(data)

Registered names:

benchmarks/bench_sort.py::bench_sort[n=10-algo='merge']
benchmarks/bench_sort.py::bench_sort[n=100-algo='quick']

You can override the labels with the ids argument:

@mew.parametrize(
    [{"n": 10}, {"n": 1000}],
    ids=["small", "large"],
)
def bench(state, n): ...

If you do this, the length of ids must be equal to the number of parametrizations.

@mew.product

For when the variants are a cartesian product of independent axes:

@mew.product(n=[10, 100, 1000], algo=["merge", "quick"], tags="sort")
def bench_sort(state, n, algo): ...

This registers six benchmarks in total. Use ids= to supply a flat list of labels, length must again equal the product size.

See mew.parametrize() and mew.product() for full parameter docs.

Picking between them

  • Reach for @product when the axes are independent and you genuinely want every combination.

  • Reach for @parametrize when only certain pairings are meaningful, e.g. when some algorithms only support certain sizes.

  • Need both styles in one file? Define multiple functions; the registry is a flat list and order doesn’t matter.

Filtering at run time

Filter by variant label via the global -k pattern (substring match):

$ mew run -k 'algo=quick'
$ mew run -k 'n=1000'

You can also apply discovery and filtering in one shot by using the selector form:

$ mew run 'benchmarks/bench_sort.py::n=1000'