ruff/scripts/benchmarks
Charlie Marsh 4df9e07a79
Add a benchmarking script for the formatter CLI (#7340)
## Summary

This PR adds a benchmarking script for the formatter, which benchmarks
the Ruff formatter against Black, yapf, and autopep8.

Three benchmarks are included:

1. Format everything.
2. Format everything, but use a single thread.
3. Format everything, but `--check` (don't write to disk).

There's some nuance in figuring out the right combination of arguments
to each command, but the _main_ nuance is to ensure that we always run
the given formatter (and modify the target repo in-place) prior to
benchmarking it, so that the formatters aren't disadvantaged by the
existing formatting of the target repo. (E.g.: prior to benchmarking
Black's preview style, we need to make sure we format the target repo
with Black's preview style; otherwise, preview style appears much
slower.)

Part of https://github.com/astral-sh/ruff/issues/7309.
2023-09-13 13:15:48 -04:00
..
dark.svg Re-run benchmark and update documentation (#1907) 2023-01-16 01:38:58 -05:00
graph-spec.json Re-run benchmark and update documentation (#1907) 2023-01-16 01:38:58 -05:00
light.svg Re-run benchmark and update documentation (#1907) 2023-01-16 01:38:58 -05:00
poetry.lock Add a benchmarking script for the formatter CLI (#7340) 2023-09-13 13:15:48 -04:00
pyproject.toml Add a benchmarking script for the formatter CLI (#7340) 2023-09-13 13:15:48 -04:00
README.md markdownlint: enforce 100 char max length (#4698) 2023-05-28 22:45:56 -04:00
run.sh refactor: Introduce crates folder (#2088) 2023-02-05 16:47:48 -05:00
run_all.sh refactor: Introduce crates folder (#2088) 2023-02-05 16:47:48 -05:00
run_comparisons.sh refactor: Introduce crates folder (#2088) 2023-02-05 16:47:48 -05:00
run_formatter.sh Add a benchmarking script for the formatter CLI (#7340) 2023-09-13 13:15:48 -04:00
run_plugins.sh refactor: Introduce crates folder (#2088) 2023-02-05 16:47:48 -05:00
run_silent.sh refactor: Introduce crates folder (#2088) 2023-02-05 16:47:48 -05:00
setup.sh Use --filter=blob:none to clone CPython faster (#4156) 2023-04-30 13:39:22 +02:00

benchmarks

Utilities for benchmarking Ruff.

Getting Started

Run ./scripts/benchmarks/run.sh to clone the benchmarking target (CPython).

If you're looking to benchmark Ruff against other tools, you'll also need to run poetry install to create a virtual environment with the required dependencies.

Running Benchmarks

Run ./scripts/benchmarks/run.sh to run Ruff over the target repo (CPython). The ./scripts/benchmarks folder contains a few other benchmarks (e.g., scripts/benchmarks/run_comparisons.sh compares Ruff to a variety of other tools).

Generating Plots

The Vega specification for the benchmark plot depicted in the root README can be found at scripts/benchmarks/graph-spec.json. You can render this JSON spec in the Vega Editor.

The images seen in the README are generated by exporting the rendered Vega spec as SVG (at around 688px wide) and manually bolding the Ruff title and benchmark time. The dark mode variant is generated by changing the fill from fill="#333333" to fill="#C9D1D9".