Skip to content

Commit a132e51

Browse files
committed
Add benchmarks to CI
1 parent ea72315 commit a132e51

File tree

3 files changed

+113
-9
lines changed

3 files changed

+113
-9
lines changed

.github/workflows/benchmark.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Benchmark PR vs main
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
paths:
9+
- '**.swift'
10+
- '**.yml'
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}-benchmark
14+
cancel-in-progress: true
15+
16+
jobs:
17+
benchmark-delta:
18+
19+
runs-on: ${{ matrix.os }}
20+
timeout-minutes: 15
21+
continue-on-error: true
22+
permissions:
23+
issues: write
24+
pull-requests: write
25+
26+
strategy:
27+
matrix:
28+
os: [ubuntu-latest]
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Ubuntu deps
36+
if: ${{ runner.os == 'Linux' }}
37+
run: |
38+
sudo apt-get install -y libjemalloc-dev
39+
40+
- name: Git URL token override and misc
41+
run: |
42+
#git config --global url."https://ordo-ci:${{ secrets.CI_MACHINE_PAT }}@github.com".insteadOf "https://github.com"
43+
#/usr/bin/ordo-performance
44+
[ -d Benchmarks ] && echo "hasBenchmark=1" >> $GITHUB_ENV
45+
echo "/opt/homebrew/bin:/usr/local/bin" >> $GITHUB_PATH
46+
- name: Run benchmarks for PR branch
47+
if: ${{ env.hasBenchmark == '1' }}
48+
run: |
49+
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update pull_request
50+
- name: Switch to branch 'main'
51+
if: ${{ env.hasBenchmark == '1' }}
52+
run: |
53+
git stash
54+
git checkout main
55+
- name: Run benchmarks for branch 'main'
56+
if: ${{ env.hasBenchmark == '1' }}
57+
run: |
58+
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update main
59+
- name: Compare PR and main
60+
if: ${{ env.hasBenchmark == '1' }}
61+
id: benchmark
62+
run: |
63+
echo '## Summary' >> $GITHUB_STEP_SUMMARY
64+
echo $(date) >> $GITHUB_STEP_SUMMARY
65+
echo "exitStatus=1" >> $GITHUB_ENV
66+
swift package benchmark baseline check main pull_request --format markdown >> $GITHUB_STEP_SUMMARY
67+
echo '---' >> $GITHUB_STEP_SUMMARY
68+
swift package benchmark baseline compare main pull_request --no-progress --quiet --format markdown >> $GITHUB_STEP_SUMMARY
69+
echo "exitStatus=0" >> $GITHUB_ENV
70+
continue-on-error: true
71+
- if: ${{ env.exitStatus == '0' }}
72+
name: Pull request comment text success
73+
id: prtestsuccess
74+
run: |
75+
echo 'PRTEST<<EOF' >> $GITHUB_ENV
76+
echo "[Pull request benchmark comparison [${{ matrix.os }}] with 'main' run at $(date -Iseconds)](https://github.com/hummingbird-project/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }})" >> $GITHUB_ENV
77+
echo 'EOF' >> $GITHUB_ENV
78+
- if: ${{ env.exitStatus == '1' }}
79+
name: Pull request comment text failure
80+
id: prtestfailure
81+
run: |
82+
echo 'PRTEST<<EOF' >> $GITHUB_ENV
83+
echo "[Pull request benchmark comparison [${{ matrix.os }}] with 'main' run at $(date -Iseconds)](https://github.com/hummingbird-project/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }})" >> $GITHUB_ENV
84+
echo "_Pull request had performance regressions_" >> $GITHUB_ENV
85+
echo 'EOF' >> $GITHUB_ENV
86+
- name: Comment PR
87+
if: ${{ env.hasBenchmark == '1' }}
88+
uses: thollander/actions-comment-pull-request@v3
89+
with:
90+
github-token: ${{ secrets.GITHUB_TOKEN }}
91+
message: ${{ env.PRTEST }}
92+
comment-tag: benchmark
93+
- name: Exit with correct status
94+
run: |
95+
exit ${{ env.exitStatus }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ DerivedData/
77
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
88
.netrc
99
.vscode
10-
Package.resolved
10+
Package.resolved
11+
.benchmarkBaselines/

Benchmarks/ValkeyBenchmarks/ValkeyBenchmarks.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,27 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import Benchmark
16+
import Foundation
1617
import Logging
1718
import NIOCore
1819
import NIOPosix
1920
import Valkey
2021

21-
let benchmarks : @Sendable () -> Void = {
22-
let defaultMetrics: [BenchmarkMetric] = [
23-
.wallClock,
24-
.cpuTotal,
25-
.mallocCountTotal,
26-
.throughput,
27-
.instructions,
28-
]
22+
let benchmarks: @Sendable () -> Void = {
23+
let defaultMetrics: [BenchmarkMetric] =
24+
// There is no point comparing wallClock, cpuTotal or throughput on CI as they are too inconsistent
25+
ProcessInfo.processInfo.environment["CI"] != nil
26+
? [
27+
.mallocCountTotal,
28+
.instructions,
29+
]
30+
: [
31+
.wallClock,
32+
.cpuTotal,
33+
.mallocCountTotal,
34+
.throughput,
35+
.instructions,
36+
]
2937

3038
var server: Channel?
3139
Benchmark("GET benchmark", configuration: .init(metrics: defaultMetrics, scalingFactor: .kilo)) { benchmark in

0 commit comments

Comments
 (0)