From 7bb21ae0e6497e6badc1e4bab1a2bfa0617f689b Mon Sep 17 00:00:00 2001 From: Aric Coady Date: Sun, 16 Jun 2024 15:52:07 -0700 Subject: [PATCH] Codspeed benchmarks. --- .github/workflows/build.yml | 4 ++-- .github/workflows/codspeed.yml | 22 ++++++++++++++++++++++ Makefile | 3 +++ README.md | 1 + tests/requirements.in | 2 ++ tests/test_dispatch.py | 2 ++ tests/test_methods.py | 2 ++ tests/test_subscripts.py | 1 + 8 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/codspeed.yml create mode 100644 tests/requirements.in diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aa70dd4..6516ec6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,13 +12,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9', '3.10', '3.11', '3.12', '3.13.0-alpha - 3.13'] + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13.0-beta - 3.13'] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - run: pip install pytest-cov + - run: pip install -r tests/requirements.in - run: make check - run: coverage xml - uses: codecov/codecov-action@v4 diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 0000000..6ff2928 --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,22 @@ +name: codspeed-benchmarks + +on: + workflow_dispatch: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + benchmarks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - run: pip install -r tests/requirements.in + - uses: CodSpeedHQ/action@v2 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: make bench diff --git a/Makefile b/Makefile index cc2f152..d592f06 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ check: python -m pytest -s --cov +bench: + python -m pytest --codspeed + lint: ruff check . ruff format --check . diff --git a/README.md b/README.md index 3a20171..c8bd37e 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![build](https://github.com/coady/multimethod/actions/workflows/build.yml/badge.svg)](https://github.com/coady/multimethod/actions/workflows/build.yml) [![image](https://codecov.io/gh/coady/multimethod/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/multimethod/) [![CodeQL](https://github.com/coady/multimethod/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/coady/multimethod/actions/workflows/github-code-scanning/codeql) +[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/coady/multimethod) [![image](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![image](https://mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/) diff --git a/tests/requirements.in b/tests/requirements.in new file mode 100644 index 0000000..e75112c --- /dev/null +++ b/tests/requirements.in @@ -0,0 +1,2 @@ +pytest-cov +pytest-codspeed diff --git a/tests/test_dispatch.py b/tests/test_dispatch.py index be3bbca..75df512 100644 --- a/tests/test_dispatch.py +++ b/tests/test_dispatch.py @@ -36,6 +36,7 @@ def _(left, right): return 'paper covers rock' +@pytest.mark.benchmark def test_roshambo(): assert roshambo.__name__ == 'roshambo' r, p, s = rock(), paper(), scissors() @@ -103,6 +104,7 @@ def func(a: int, b: float = 0.0): assert multimethod(bool)(1) +@pytest.mark.benchmark def test_keywords(): @multidispatch def func(arg): diff --git a/tests/test_methods.py b/tests/test_methods.py index 2fbb208..3f6bc37 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -51,6 +51,7 @@ def subclass(*bases, **kwds): return types.new_class('', bases, kwds) +@pytest.mark.benchmark def test_subtype(): assert len({subtype(list[int]), subtype(list[int])}) == 1 assert len({subtype(list[bool]), subtype(list[int])}) == 2 @@ -76,6 +77,7 @@ def test_subtype(): assert not list(subtype.origins(subclass(Protocol[TypeVar('T')]))) +@pytest.mark.benchmark def test_signature(): assert signature([Any, list, NewType('', int)]) == (object, list, int) assert signature([AnyStr]) == signature([Union[bytes, str]]) diff --git a/tests/test_subscripts.py b/tests/test_subscripts.py index 41a3843..cd946a3 100644 --- a/tests/test_subscripts.py +++ b/tests/test_subscripts.py @@ -128,6 +128,7 @@ def test_args(): assert subtype(typing.Callable) is Callable +@pytest.mark.benchmark def test_parametric(): coro = parametric(Callable, asyncio.iscoroutinefunction) assert issubclass(coro, Callable)