Skip to content

Commit

Permalink
ci: add codspeed benchmarking (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff authored Feb 10, 2024
2 parents b4ee80e + d5e9219 commit 91d78bc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: codspeed-benchmarks

on:
push:
branches:
- "main"
pull_request:
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install dependencies
run: pip install .[dev]

- name: Run benchmarks
uses: CodSpeedHQ/action@v2
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: pytest --codspeed
8 changes: 8 additions & 0 deletions iterpy/test_iter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from collections.abc import Sequence

import pytest

from iterpy._iter import Iter


Expand Down Expand Up @@ -103,6 +105,12 @@ def test_flatten():
assert result.to_list() == [1, 2, 3, 4]


@pytest.mark.benchmark()
def test_benchmark_large_flattening():
test_input = Iter(range(100_000)).map(lambda x: Iter([x]))
assert test_input.flatten().to_list() == list(range(100_000))


class TestFlattenTypes:
"""Intentionally not parametrised so we can manually specify the return type hints and they can be checked by pyright"""

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dev = [
"pytest-cov==4.1.0",
"pytest-xdist==3.5.0",
"pytest-sugar==1.0.0",
"pytest-codspeed",
"diff-cover==8.0.3",
"ruff==0.2.0",
]
Expand Down

0 comments on commit 91d78bc

Please sign in to comment.