Skip to content

Commit 0b1fe94

Browse files
committed
Add benchmark job in CI
1 parent 157f03c commit 0b1fe94

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/pull_request.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,51 @@ jobs:
1919
license_header_check_project_name: "Swift.org"
2020
unacceptable_language_check_enabled: false
2121
format_check_enabled: false
22+
bench:
23+
runs-on: ubuntu-latest
24+
env:
25+
BUILD_CMD: swift build -c release
26+
BENCH_CMD: .build/release/RegexBenchmark
27+
BASELINE_FILE: benchmark-main
28+
COMPARE_OUT_FILE: benchmark-results.txt
29+
steps:
30+
- name: Check out PR head
31+
uses: actions/checkout@v4
32+
with:
33+
ref: ${{ github.event.pull_request.head.sha }}
34+
path: pr
35+
fetch-depth: 0
36+
- name: Check out PR base
37+
uses: actions/checkout@v4
38+
with:
39+
ref: ${{ github.event.pull_request.base.sha }}
40+
path: base
41+
fetch-depth: 0
42+
- name: Build base
43+
working-directory: base
44+
run: |
45+
set -euo pipefail
46+
eval "$BUILD_CMD"
47+
- name: Run baseline benchmark
48+
working-directory: base
49+
run: |
50+
set -euo pipefail
51+
eval "$BENCH_CMD --save $RUNNER_TEMP/$BASELINE_FILE"
52+
test -s "$RUNNER_TEMP/$BASELINE_FILE" || { echo "Baseline not created at $BASELINE_FILE"; exit 1; }
53+
- name: Build PR
54+
working-directory: pr
55+
run: |
56+
set -euo pipefail
57+
eval "$BUILD_CMD"
58+
- name: Run comparison benchmark (PR vs main)
59+
working-directory: pr
60+
run: |
61+
set -euo pipefail
62+
eval "$BENCH_CMD --compare $RUNNER_TEMP/$BASELINE_FILE" | tee "$RUNNER_TEMP/$COMPARE_OUT_FILE"
63+
- name: Upload benchmark artifacts
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: benchmark-results
67+
path: |
68+
${{ env.BASELINE_FILE }}
69+
${{ env.COMPARE_OUT_MD }}

0 commit comments

Comments
 (0)