-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (144 loc) · 4.61 KB
/
benchmark.yml
File metadata and controls
170 lines (144 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Benchmark
on:
push:
branches: [ main ]
paths:
- '**.go'
- 'src/**'
- 'Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/benchmark.yml'
- '.github/actions/**'
pull_request:
branches: [ main ]
paths:
- '**.go'
- 'src/**'
- 'Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/benchmark.yml'
- '.github/actions/**'
workflow_dispatch:
permissions:
contents: write
deployments: write
pull-requests: write
jobs:
benchmark:
name: Run Go benchmarks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
- name: Setup Rust
uses: ./.github/actions/setup-rust
- name: Build Rust library
run: cargo build --release --locked
- name: Run benchmarks
run: |
set -o pipefail
export TOKENIZERS_LIB_PATH="${{ github.workspace }}/target/release/libtokenizers.so"
go test -bench=. -benchmem -count=5 ./... | tee benchmark_output.txt
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: Go Benchmark
tool: 'go'
output-file-path: benchmark_output.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
alert-threshold: '120%'
comment-on-alert: true
fail-on-alert: false
alert-comment-cc-users: '@tazarov'
summary-always: true
- name: Upload benchmark results
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: benchmark_output.txt
retention-days: 30
benchmark-compare:
name: Compare benchmarks (PR)
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout PR code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
- name: Setup Rust
uses: ./.github/actions/setup-rust
- name: Install benchstat
run: go install golang.org/x/perf/cmd/benchstat@latest
- name: Build Rust library
run: cargo build --release --locked
- name: Run benchmarks on PR branch
run: |
export TOKENIZERS_LIB_PATH="${{ github.workspace }}/target/release/libtokenizers.so"
go test -bench=. -benchmem -count=5 ./... > pr_bench.txt
- name: Checkout base branch
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
path: base
- name: Build base branch
working-directory: base
run: cargo build --release
- name: Run benchmarks on base branch
working-directory: base
continue-on-error: true
run: |
export TOKENIZERS_LIB_PATH="${{ github.workspace }}/base/target/release/libtokenizers.so"
go test -bench=. -benchmem -count=5 ./... > ../base_bench.txt || echo "No benchmarks found in base branch" > ../base_bench.txt
- name: Compare benchmarks
run: |
echo "## Benchmark Comparison" > benchmark_comment.md
echo "" >> benchmark_comment.md
echo "\`\`\`" >> benchmark_comment.md
benchstat base_bench.txt pr_bench.txt >> benchmark_comment.md || true
echo "\`\`\`" >> benchmark_comment.md
cat benchmark_comment.md
- name: Comment PR with benchmark results
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const comment = fs.readFileSync('benchmark_comment.md', 'utf8');
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
// Find and update existing comment or create new one
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('## Benchmark Comparison')
);
if (botComment) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: botComment.id,
body: comment
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: comment
});
}