-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
141 lines (128 loc) · 4.96 KB
/
benchmark.yml
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
on:
push:
branches:
- master
- main
paths-ignore:
- "**/*.md"
pull_request:
paths-ignore:
- "**/*.md"
permissions:
# deployments permission to deploy GitHub pages website
deployments: write
# contents permission to update benchmark contents in gh-pages branch
contents: write
# allow posting comments to pull request
pull-requests: write
name: Benchmark
jobs:
Compare:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # to be able to retrieve the last commit in main
- name: Install Go
uses: actions/setup-go@v5
with:
# NOTE: Keep this in sync with the version from go.mod
go-version: "1.23.x"
- name: Run Benchmark
run: set -o pipefail; go test ./... -benchmem -run=^$ -bench . | tee output.txt
### hack because of the problem with duplicated benchmark names - https://github.com/benchmark-action/github-action-benchmark/issues/264
- name: Extract Module Name
id: extract-module
run: |
MODULE_NAME=$(awk '/^module / {print $2}' go.mod)
echo "MODULE_NAME=$MODULE_NAME" >> $GITHUB_ENV
- name: Identify Duplicate Benchmark Names
run: |
awk '/^Benchmark/ {print $1}' output.txt | sort | uniq -d > duplicate_benchmarks.txt
- name: Add Normalized Package Prefix to Duplicate Benchmark Names
run: |
awk -v MODULE_NAME="$MODULE_NAME" '
FNR==NR {duplicates[$1]; next}
/^pkg: / { package=$2 }
/^Benchmark/ {
if ($1 in duplicates) {
sub("^" MODULE_NAME "/?", "", package)
gsub("/", "_", package)
print $1 "_" package substr($0, length($1) + 1)
} else {
print $0
}
next
}
{ print }
' duplicate_benchmarks.txt output.txt > output_prefixed.txt
mv output_prefixed.txt output.txt
### end
# NOTE: Benchmarks could change with different CPU types
- name: Get GitHub Runner System Information
uses: kenchan0130/[email protected]
id: system-info
- name: Get Main branch SHA
id: get-main-branch-sha
run: |
SHA=$(git rev-parse origin/main)
echo "sha=$SHA" >> $GITHUB_OUTPUT
- name: Get Benchmark Results from main branch
id: cache
uses: actions/cache/restore@v4
with:
path: ./cache
key: ${{ steps.get-main-branch-sha.outputs.sha }}-${{ runner.os }}-${{ steps.system-info.outputs.cpu-model }}-benchmark
# This will only run if we have Benchmark Results from main branch
- name: Compare PR Benchmark Results with main branch
uses: benchmark-action/[email protected]
if: steps.cache.outputs.cache-hit == 'true'
with:
tool: 'go'
output-file-path: output.txt
external-data-json-path: ./cache/benchmark-data.json
# Do not save the data (This allows comparing benchmarks)
save-data-file: false
fail-on-alert: true
# Comment on the PR if the branch is not a fork
comment-on-alert: ${{ github.event.pull_request.head.repo.fork == false }}
github-token: ${{ secrets.GITHUB_TOKEN }}
summary-always: true
alert-threshold: "150%"
- name: Store Benchmark Results for main branch
uses: benchmark-action/[email protected]
if: ${{ github.ref_name == 'main' }}
with:
tool: 'go'
output-file-path: output.txt
external-data-json-path: ./cache/benchmark-data.json
# Save the data to external file (cache)
save-data-file: true
fail-on-alert: false
github-token: ${{ secrets.GITHUB_TOKEN }}
summary-always: true
alert-threshold: "150%"
- name: Publish Benchmark Results to GitHub Pages
uses: benchmark-action/[email protected]
if: ${{ github.ref_name == 'main' }}
with:
tool: 'go'
output-file-path: output.txt
benchmark-data-dir-path: "benchmarks"
fail-on-alert: false
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-on-alert: true
summary-always: true
# Save the data to external file (GitHub Pages)
save-data-file: true
alert-threshold: "150%"
# TODO: reactivate it later -> when v3 is the stable one
#auto-push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
auto-push: false
- name: Update Benchmark Results cache
uses: actions/cache/save@v4
if: ${{ github.ref_name == 'main' }}
with:
path: ./cache
key: ${{ steps.get-main-branch-sha.outputs.sha }}-${{ runner.os }}-${{ steps.system-info.outputs.cpu-model }}-benchmark