Metadata-Version: 2.4
Name: mew-bench
Version: 0.4.0
Summary: A CLI for microbenchmarking Python code snippets.
Keywords: benchmarking,microbenchmark,performance,profiling
Author-Email: Nicholas Junge <nicho.junge@gmail.com>
License-Expression: Apache-2.0 AND BSD-3-Clause AND MIT
License-File: LICENSE
License-File: licenses/google-benchmark.txt
License-File: licenses/nanobind.txt
License-File: licenses/robin-map.txt
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: System :: Benchmark
Classifier: Typing :: Typed
Project-URL: Documentation, https://mew.readthedocs.io
Project-URL: Repository, https://github.com/nicholasjng/mew
Project-URL: Issues, https://github.com/nicholasjng/mew/issues
Project-URL: Changelog, https://mew.readthedocs.io/en/latest/changelog.html
Requires-Python: >=3.11
Provides-Extra: cpu
Requires-Dist: pyinstrument>=4.6; extra == "cpu"
Provides-Extra: memory
Requires-Dist: memray>=1.15.0; sys_platform != "win32" and extra == "memory"
Description-Content-Type: text/markdown

# mew

[![Documentation Status](https://readthedocs.org/projects/mew/badge/?version=latest)](https://mew.readthedocs.io/en/latest/)
[![CI](https://github.com/nicholasjng/mew/actions/workflows/ci.yml/badge.svg)](https://github.com/nicholasjng/mew/actions/workflows/ci.yml)

mew measures the cost of Python code using [Google Benchmark](https://github.com/google/benchmark).
Write a benchmark function and run it from Python or the command line.

```python
import mew


@mew.benchmark
def bench_sorted(state: mew.State) -> None:
    data = list(range(1000, 0, -1))
    for _ in state:
        sorted(data)
```

Save this as `benchmarks/bench_sort.py`, then run:

```console
$ mew run --repetitions 10 -o baseline.json
```

Setup before the loop is excluded from timing.
mew chooses an iteration count and reports wall-clock and CPU time per iteration.
After changing the code under test, measure again and compare against the baseline:

```console
$ mew run --repetitions 10 -o candidate.json
$ mew compare baseline.json candidate.json
```

You can parametrize inputs, run benchmarks from a Python script, and save results as JSON or an appendable JSONL archive.
Optional CPU and memory profilers help investigate changes.

## Installation

```console
$ pip install mew-bench
# Or, in a uv project:
$ uv add --dev mew-bench
```

Requires Python 3.11 or later.
A prebuilt wheel is installed where available.
Other platforms compile the C++ extension from source.

## Documentation

- [Quickstart](https://mew.readthedocs.io/en/latest/quickstart.html)
- [Writing and measuring benchmarks](https://mew.readthedocs.io/en/latest/guide/writing-benchmarks.html)
- [Comparing and gating](https://mew.readthedocs.io/en/latest/guide/comparing.html)
- [Using the Python API](https://mew.readthedocs.io/en/latest/guide/python-api.html)
- [Recipes](https://mew.readthedocs.io/en/latest/recipes/index.html), including [gating pull requests on regressions](https://mew.readthedocs.io/en/latest/recipes/ci-gate.html) and [tracking JAX through Git history](https://mew.readthedocs.io/en/latest/recipes/git-history.html)
- [API reference](https://mew.readthedocs.io/en/latest/reference/api/index.html) and [CLI reference](https://mew.readthedocs.io/en/latest/reference/cli.html)

## License

The project license is Apache-2.0.
Bundled third-party code also carries BSD-3-Clause and MIT licenses, see [LICENSE](LICENSE) and [licenses/](licenses/).
