diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 69e106a0..4868eb8d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,6 +5,7 @@ on: branches: main pull_request: branches: main + workflow_dispatch: jobs: pytest: @@ -32,6 +33,30 @@ jobs: name: coverage-reports path: ./coverage.xml + benchmarks: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + python: [3.9] + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + architecture: x64 + - name: Install dependencies + run: | + python -m pip install --upgrade uv + uv pip install --system -e ".[test]" + - name: Run benchmarks + uses: CodSpeedHQ/action@v3 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: pytest --codspeed tests/ + codecov-upload: runs-on: ubuntu-latest needs: pytest diff --git a/pyproject.toml b/pyproject.toml index d47fab77..b37266d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,7 @@ test = [ "pytest>=7.3.2", "pytest-cov>=3.0.0,<5.0.0", "pytest-pretty>=1.0.0,<2.0.0", + "pytest-codspeed>=2.2.1,<3.0.0", ] quality = [ "ruff==0.5.7", @@ -76,6 +77,7 @@ dev = [ "pytest>=7.3.2", "pytest-cov>=4.0.0,<5.0.0", "pytest-pretty>=1.0.0,<2.0.0", + "pytest-codspeed>=2.2.1,<3.0.0", # style "ruff==0.5.7", "mypy==1.10.0", diff --git a/tests/test_metrics.py b/tests/test_metrics.py index d3e2f30d..6d0aecc9 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -1,5 +1,6 @@ from functools import partial +import pytest import torch from torchvision.models import mobilenet_v3_small @@ -7,6 +8,7 @@ from torchcam.methods import LayerCAM +@pytest.mark.benchmark def test_classification_metric(): model = mobilenet_v3_small(weights=None) with LayerCAM(model, "features.12") as extractor: