1+ # This script is provided by github.com/bool64/dev.
12name : bench
23on :
3- push :
4- tags :
5- - v*
6- branches :
7- - master
8- - main
94 pull_request :
5+ workflow_dispatch :
6+ inputs :
7+ old :
8+ description : ' Old Ref'
9+ required : false
10+ default : ' master'
11+ new :
12+ description : ' New Ref'
13+ required : true
14+
1015env :
1116 GO111MODULE : " on"
17+ CACHE_BENCHMARK : " off" # Enables benchmark result reuse between runs, may skew latency results.
18+ RUN_BASE_BENCHMARK : " on" # Runs benchmark for PR base in case benchmark result is missing.
1219jobs :
1320 bench :
1421 strategy :
1522 matrix :
16- go-version : [ 1.15 .x ]
23+ go-version : [ 1.17 .x ]
1724 runs-on : ubuntu-latest
1825 steps :
1926 - name : Install Go
@@ -22,33 +29,57 @@ jobs:
2229 go-version : ${{ matrix.go-version }}
2330 - name : Checkout code
2431 uses : actions/checkout@v2
25- - name : Restore vendor
32+ with :
33+ ref : ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
34+ - name : Go cache
2635 uses : actions/cache@v2
2736 with :
37+ # In order:
38+ # * Module download cache
39+ # * Build cache (Linux)
2840 path : |
29- vendor
30- key : ${{ runner.os }}-go${{ matrix.go-version }}-vendor-${{ hashFiles('** /go.mod') }}
31- - name : Populate dependencies
32- run : |
33- (test -d vendor && echo vendor found) || (go mod vendor && du -sh vendor && du -sh ~/go/pkg/mod)
41+ ~/go/pkg/mod
42+ ~/.cache /go-build
43+ key : ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
44+ restore-keys : |
45+ ${{ runner.os }}-go-cache
3446 - name : Restore benchstat
3547 uses : actions/cache@v2
3648 with :
3749 path : ~/go/bin/benchstat
3850 key : ${{ runner.os }}-benchstat
3951 - name : Restore base benchmark result
52+ if : env.CACHE_BENCHMARK == 'on'
53+ id : benchmark-base
4054 uses : actions/cache@v2
4155 with :
4256 path : |
4357 bench-master.txt
4458 bench-main.txt
4559 # Use base sha for PR or new commit hash for master/main push in benchmark result key.
4660 key : ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
61+ - name : Checkout base code
62+ if : env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
63+ uses : actions/checkout@v2
64+ with :
65+ ref : ${{ (github.event.pull_request.base.sha != '' ) && github.event.pull_request.base.sha || github.event.inputs.old }}
66+ path : __base
67+ - name : Run base benchmark
68+ if : env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
69+ run : |
70+ export REF_NAME=master
71+ cd __base
72+ make | grep bench-run && (BENCH_COUNT=5 make bench-run bench-stat && cp bench-master.txt ../bench-master.txt) || echo "No benchmarks in base"
4773 - name : Benchmark
4874 id : bench
4975 run : |
50- export REF_NAME=${GITHUB_REF##*/}
51- BENCH_COUNT=5 make bench-run bench-stat
76+ export REF_NAME=new
77+ BENCH_COUNT=5 make bench
78+ OUTPUT=$(make bench-stat-diff)
79+ OUTPUT="${OUTPUT//'%'/'%25'}"
80+ OUTPUT="${OUTPUT//$'\n'/'%0A'}"
81+ OUTPUT="${OUTPUT//$'\r'/'%0D'}"
82+ echo "::set-output name=diff::$OUTPUT"
5283 OUTPUT=$(make bench-stat)
5384 OUTPUT="${OUTPUT//'%'/'%25'}"
5485 OUTPUT="${OUTPUT//$'\n'/'%0A'}"
6394 ### Benchmark Result
6495 <details><summary>Benchmark diff with base branch</summary>
6596
97+ ```
98+ ${{ steps.bench.outputs.diff }}
99+ ```
100+ </details>
101+
102+ <details><summary>Benchmark result</summary>
103+
66104 ```
67105 ${{ steps.bench.outputs.result }}
68106 ```
0 commit comments