Add benchmarks framework #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Benchmarks | |
| on: | |
| pull_request: | |
| types: [labeled, synchronize] | |
| push: | |
| branches: [main] | |
| jobs: | |
| benchmark-cpu: | |
| # Only run on PRs with 'run-benchmarks' label OR on main branch | |
| if: | | |
| github.event_name == 'push' || | |
| contains(github.event.pull_request.labels.*.name, 'run-benchmarks') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| - name: Install dependencies | |
| run: uv sync --extra benchmark | |
| - name: Run benchmarks with CodSpeed | |
| uses: CodSpeedHQ/action@v3 | |
| with: | |
| token: ${{ secrets.CODSPEED_TOKEN }} | |
| run: uv run pytest benchmarks/ --codspeed -m "not slow and not integration" | |
| - name: Generate benchmark JSON (fallback) | |
| if: always() | |
| run: | | |
| uv run pytest benchmarks/ \ | |
| --benchmark-only \ | |
| --benchmark-json=benchmark-results.json \ | |
| -m "not slow and not integration" || true | |
| - name: Upload benchmark results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: benchmark-results | |
| path: benchmark-results.json | |
| retention-days: 30 | |
| benchmark-memory: | |
| # Only run on PRs with 'run-benchmarks' label | |
| if: contains(github.event.pull_request.labels.*.name, 'run-benchmarks') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| - name: Install dependencies | |
| run: uv sync --extra benchmark | |
| - name: Run memory benchmarks | |
| run: | | |
| uv run pytest benchmarks/ \ | |
| --memray \ | |
| --memray-bin-path=memray-results \ | |
| -m "not slow and not integration" | |
| - name: Upload memory results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: memory-results | |
| path: memray-results/ | |
| retention-days: 30 |