Skip to content

Commit

Permalink
Codspeed benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
coady committed Jun 16, 2024
1 parent b22fc5b commit 7bb21ae
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
check:
python -m pytest -s --cov

bench:
python -m pytest --codspeed

lint:
ruff check .
ruff format --check .
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

Expand Down
2 changes: 2 additions & 0 deletions tests/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest-cov
pytest-codspeed
2 changes: 2 additions & 0 deletions tests/test_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]])
Expand Down
1 change: 1 addition & 0 deletions tests/test_subscripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7bb21ae

Please sign in to comment.