Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

</details>

Expand Down
40 changes: 40 additions & 0 deletions tests/test_benchmarks.py
Original file line number Diff line number Diff line change
@@ -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
Loading