-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (105 loc) · 3.65 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
name: benchmark
on:
pull_request:
workflow_dispatch:
inputs:
old:
description: 'Old Ref'
required: false
default: 'main'
new:
description: 'New Ref'
required: true
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
GO111MODULE: "on"
CACHE_BENCHMARK: "off"
RUN_BASE_BENCHMARK: "on"
GO_VERSION: 1.22.x
jobs:
benchmark:
strategy:
matrix:
go-version: [ 1.22.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go stable
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
- name: Go cache
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-cache
- name: Restore benchstat
uses: actions/cache@v3
with:
path: ~/go/bin/benchstat
key: ${{ runner.os }}-benchstat-legacy
- name: Restore base benchmark result
id: base-benchmark
if: env.CACHE_BENCHMARK == 'on'
uses: actions/cache@v3
with:
path: |
bench-master.txt
bench-main.txt
key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
- name: Run benchmark
run: |
export REF_NAME=new
cd benchmarks && make benchmark-ci
OUTPUT=$(make bench-stat-diff)
echo "${OUTPUT}"
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
OUTPUT=$(make bench-stat)
echo "${OUTPUT}"
echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
- name: Run benchmark for base code
if: env.RUN_BASE_BENCHMARK == 'on' && steps.base-benchmark.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
run: |
git fetch origin main ${{ github.event.pull_request.base.sha }}
HEAD=$(git rev-parse HEAD)
git reset --hard ${{ github.event.pull_request.base.sha }}
export REF_NAME=main
cd benchmarks && make bench-run bench-stat
git reset --hard $HEAD
- name: Benchmark stats
id: benchmark
run: |
export REF_NAME=new
cd benchmarks
OUTPUT=$(make bench-stat-diff)
echo "${OUTPUT}"
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
OUTPUT=$(make bench-stat)
echo "${OUTPUT}"
echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
- name: Comment benchmark result
continue-on-error: true
uses: marocchino/sticky-pull-request-comment@v2
with:
header: benchmark
message: |
### Benchmark Result
<details><summary>Benchmark diff with base branch</summary>
```
${{ steps.benchmark.outputs.diff }}
```
</details>
<details><summary>Benchmark result</summary>
```
${{ steps.benchmark.outputs.result }}
```
</details>