|
| 1 | +name: Benchmarks |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - "tesseract_core/**" |
| 7 | + - "benchmarks/**" |
| 8 | + - ".github/workflows/benchmarks.yml" |
| 9 | + - "benchmarks/compare_benchmarks.py" |
| 10 | + |
| 11 | + push: |
| 12 | + branches: |
| 13 | + - main |
| 14 | + paths: |
| 15 | + - "tesseract_core/**" |
| 16 | + - "benchmarks/**" |
| 17 | + - ".github/workflows/benchmarks.yml" |
| 18 | + - "benchmarks/compare_benchmarks.py" |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: benchmarks-${{ github.event.pull_request.number || github.ref }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +permissions: |
| 25 | + contents: read |
| 26 | + pull-requests: write |
| 27 | + |
| 28 | +jobs: |
| 29 | + benchmark: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Set up Git repository |
| 34 | + uses: actions/checkout@v6 |
| 35 | + |
| 36 | + - name: Set up Python |
| 37 | + uses: actions/setup-python@v6 |
| 38 | + with: |
| 39 | + python-version: "3.13" |
| 40 | + |
| 41 | + - name: Set up uv |
| 42 | + uses: astral-sh/setup-uv@v7 |
| 43 | + with: |
| 44 | + enable-cache: true |
| 45 | + |
| 46 | + - name: Restore UV environment |
| 47 | + run: cp production.uv.lock uv.lock |
| 48 | + |
| 49 | + - name: Install package |
| 50 | + run: uv sync --extra dev --frozen |
| 51 | + |
| 52 | + - name: Run benchmarks on current commit |
| 53 | + run: | |
| 54 | + uv run --no-sync python benchmarks/run_benchmarks.py \ |
| 55 | + --iterations 10 \ |
| 56 | + --array-sizes 100,10000,1000000 \ |
| 57 | + --output current_benchmarks.json |
| 58 | +
|
| 59 | + - name: Check out baseline branch |
| 60 | + if: github.event_name == 'pull_request' |
| 61 | + uses: actions/checkout@v6 |
| 62 | + with: |
| 63 | + ref: ${{ github.event.pull_request.base.ref }} |
| 64 | + path: baseline |
| 65 | + |
| 66 | + - name: Install package (baseline) |
| 67 | + if: github.event_name == 'pull_request' |
| 68 | + working-directory: baseline |
| 69 | + run: | |
| 70 | + cp production.uv.lock uv.lock 2>/dev/null || true |
| 71 | + uv sync --extra dev --frozen |
| 72 | +
|
| 73 | + - name: Run benchmarks on baseline |
| 74 | + if: github.event_name == 'pull_request' |
| 75 | + id: baseline |
| 76 | + working-directory: baseline |
| 77 | + run: | |
| 78 | + if [ -f benchmarks/run_benchmarks.py ]; then |
| 79 | + uv run --no-sync python benchmarks/run_benchmarks.py \ |
| 80 | + --iterations 10 \ |
| 81 | + --array-sizes 100,10000,1000000 \ |
| 82 | + --output baseline_benchmarks.json |
| 83 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 84 | + else |
| 85 | + echo "::notice::Benchmark script not found in baseline, skipping comparison" |
| 86 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 87 | + fi |
| 88 | +
|
| 89 | + - name: Generate comparison report |
| 90 | + if: github.event_name == 'pull_request' |
| 91 | + id: comparison |
| 92 | + run: | |
| 93 | + python benchmarks/compare_benchmarks.py \ |
| 94 | + baseline/baseline_benchmarks.json \ |
| 95 | + current_benchmarks.json \ |
| 96 | + benchmark_report.md |
| 97 | +
|
| 98 | + # Set output as multiline string |
| 99 | + { |
| 100 | + echo 'report<<BENCHMARK_REPORT_END' |
| 101 | + cat benchmark_report.md |
| 102 | + echo '' |
| 103 | + echo 'BENCHMARK_REPORT_END' |
| 104 | + } >> $GITHUB_OUTPUT |
| 105 | +
|
| 106 | + - name: Find existing comment |
| 107 | + if: github.event_name == 'pull_request' |
| 108 | + uses: peter-evans/find-comment@v3 |
| 109 | + id: find-comment |
| 110 | + with: |
| 111 | + issue-number: ${{ github.event.pull_request.number }} |
| 112 | + comment-author: "PasteurBot" |
| 113 | + body-includes: "## Benchmark Results" |
| 114 | + |
| 115 | + - name: Create or update PR comment |
| 116 | + if: github.event_name == 'pull_request' |
| 117 | + uses: peter-evans/create-or-update-comment@v4 |
| 118 | + with: |
| 119 | + token: ${{ secrets.PL_PASTEURBOT_PAT_PUBLIC }} |
| 120 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 121 | + issue-number: ${{ github.event.pull_request.number }} |
| 122 | + body: ${{ steps.comparison.outputs.report }} |
| 123 | + edit-mode: replace |
| 124 | + |
| 125 | + - name: Upload benchmark results |
| 126 | + uses: actions/upload-artifact@v7 |
| 127 | + with: |
| 128 | + name: benchmark-results |
| 129 | + path: | |
| 130 | + current_benchmarks.json |
| 131 | + baseline/baseline_benchmarks.json |
| 132 | + benchmark_report.md |
| 133 | + if-no-files-found: ignore |
| 134 | + retention-days: 30 |
0 commit comments