From 38baeae274aaa2eed54f20ec9e03f2e90cf406de Mon Sep 17 00:00:00 2001 From: "codspeed-hq[bot]" <117304815+codspeed-hq[bot]@users.noreply.github.com> Date: Tue, 14 Apr 2026 12:16:16 +0000 Subject: [PATCH] Add CodSpeed performance benchmarks and CI workflow --- .github/workflows/codspeed.yml | 55 ++++++++++++++++++++++++++++++++++ README.md | 1 + tests/test_benchmarks.py | 40 +++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 .github/workflows/codspeed.yml create mode 100644 tests/test_benchmarks.py diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 00000000..f16977e1 --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,55 @@ +name: CodSpeed + +on: + push: + branches: + - "main" + pull_request: + # `workflow_dispatch` allows CodSpeed to trigger backtest + # performance analysis in order to generate initial data. + workflow_dispatch: + +permissions: + contents: read + id-token: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + benchmarks: + + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Set up uv + uses: astral-sh/setup-uv@v7 + with: + enable-cache: true + + - name: Install dependencies + shell: bash + run: uv pip install --system -r requirements_dev.txt + + - name: Install the library + shell: bash + run: uv pip install --system . + + - name: Install pytest-codspeed + shell: bash + run: uv pip install --system pytest-codspeed + + - name: Run benchmarks + uses: CodSpeedHQ/action@v4 + with: + mode: simulation + run: pytest tests/test_benchmarks.py --codspeed diff --git a/README.md b/README.md index 615e502c..b5313c34 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ [![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/mutating/suby) +[![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/mutating/suby?utm_source=badge) diff --git a/tests/test_benchmarks.py b/tests/test_benchmarks.py new file mode 100644 index 00000000..54e42822 --- /dev/null +++ b/tests/test_benchmarks.py @@ -0,0 +1,40 @@ +from pathlib import Path + +from suby import run +from suby.run import convert_arguments, split_argument + + +def test_bench_split_argument_simple(benchmark): + """Benchmark splitting a simple command string.""" + benchmark(split_argument, 'python -c pass', False) + + +def test_bench_split_argument_with_quotes(benchmark): + """Benchmark splitting a command string with quoted arguments.""" + benchmark(split_argument, 'python -c "print(\'hello, world!\')"', False) + + +def test_bench_convert_arguments_single_string(benchmark): + """Benchmark converting a single string argument.""" + benchmark(convert_arguments, ('python -c pass',), True, False) + + +def test_bench_convert_arguments_multiple_strings(benchmark): + """Benchmark converting multiple string arguments.""" + benchmark(convert_arguments, ('python', '-c', 'print(777)'), True, False) + + +def test_bench_convert_arguments_with_path(benchmark): + """Benchmark converting arguments that include a Path object.""" + benchmark(convert_arguments, (Path('/usr/bin/python'), '-c pass'), True, False) + + +def test_bench_convert_arguments_no_split(benchmark): + """Benchmark converting arguments with split disabled.""" + benchmark(convert_arguments, ('python', '-c', 'print(777)'), False, False) + + +def test_bench_run_simple_command(benchmark): + """Benchmark running a simple subprocess end-to-end.""" + result = benchmark(run, 'python -c pass', catch_output=True) + assert result.returncode == 0