This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(circleci): add benchmark comparisons
Run benchmarks before and after, compare results
- Loading branch information
1 parent
fb007f9
commit a99af2c
Showing
5 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
version: 2.1 | ||
|
||
aliases: | ||
make_out_dirs: &make_out_dirs | ||
run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_WORKSPACE $CIRCLE_TEST_REPORTS/{bitswap} | ||
restore_gomod: &restore_gomod | ||
restore_cache: | ||
keys: | ||
- go-bitswap-dep-{{ .Branch }}-{{ checksum "~/ipfs/go-bitswap/go.sum" }}-{{ .Environment.CIRCLE_JOB }} | ||
- go-bitswap-dep-{{ .Branch }}-{{ checksum "~/ipfs/go-bitswap/go.sum" }}- | ||
- go-bitswap-dep-{{ .Branch }}- | ||
- go-bitswap-dep--master- | ||
store_gomod: &store_gomod | ||
save_cache: | ||
key: v4-dep-{{ .Branch }}-{{ checksum "~/ipfs/go-ipfs/go.sum" }}-{{ .Environment.CIRCLE_JOB }} | ||
paths: | ||
- ~/go/pkg/mod | ||
- ~/.cache/go-build/ | ||
|
||
commands: | ||
benchmark: | ||
parameters: | ||
output: | ||
type: string | ||
branch: | ||
type: string | ||
default: HEAD | ||
steps: | ||
- checkout | ||
- run: git checkout << parameters.branch >> | ||
- *make_out_dirs | ||
- *restore_gomod | ||
- run: | ||
command: go test -run=NONE -bench=. ./... | tee /tmp/circleci-workspace/<< parameters.output >> | ||
environment: | ||
IPFS_LOGGING: critical | ||
CGO_ENABLED: 0 | ||
- persist_to_workspace: | ||
root: /tmp/circleci-workspace | ||
paths: | ||
- << parameters.output >> | ||
- *store_gomod | ||
|
||
defaults: &defaults | ||
working_directory: ~/ipfs/go-ipfs | ||
environment: | ||
GO111MODULE: "on" | ||
TEST_NO_DOCKER: 1 | ||
TEST_NO_FUSE: 1 | ||
GOPATH: /home/circleci/go | ||
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results | ||
CIRCLE: 1 | ||
SERVICE: circle-ci | ||
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts | ||
CIRCLE_WORKSPACE: /tmp/circleci-workspace | ||
TEST_VERBOSE: 1 | ||
TRAVIS: 1 | ||
|
||
jobs: | ||
gobuild: | ||
docker: | ||
- image: circleci/golang:1.12 | ||
<<: *defaults | ||
steps: | ||
- checkout | ||
- *make_out_dirs | ||
- *restore_gomod | ||
- run: | ||
command: bin/build.sh | ||
|
||
- *store_gomod | ||
benchmark-release: | ||
docker: | ||
- image: circleci/golang:1.12 | ||
<<: *defaults | ||
steps: | ||
- benchmark: | ||
output: benchmark-release.txt | ||
branch: release | ||
benchmark-before: | ||
docker: | ||
- image: circleci/golang:1.12 | ||
<<: *defaults | ||
steps: | ||
- benchmark: | ||
output: benchmark-before.txt | ||
branch: master | ||
benchmark-after: | ||
docker: | ||
- image: circleci/golang:1.12 | ||
<<: *defaults | ||
steps: | ||
- benchmark: | ||
output: benchmark-after.txt | ||
benchmark-compare: | ||
docker: | ||
- image: circleci/golang:1.12 | ||
<<: *defaults | ||
steps: | ||
- checkout | ||
- *make_out_dirs | ||
- attach_workspace: | ||
at: /tmp/circleci-workspace | ||
- run: bin/diff-benchmarks.sh /tmp/circleci-workspace/benchmark-before.txt /tmp/circleci-workspace/benchmark-after.txt | ||
- run: bin/diff-benchmarks.sh /tmp/circleci-workspace/benchmark-release.txt /tmp/circleci-workspace/benchmark-after.txt | ||
|
||
workflows: | ||
version: 2 | ||
test: | ||
jobs: | ||
- gobuild | ||
- benchmark-before | ||
- benchmark-after | ||
- benchmark-release | ||
- benchmark-compare: | ||
requires: | ||
- benchmark-after | ||
- benchmark-before | ||
- benchmark-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
list_buildable() { | ||
go list -f '{{if (len .GoFiles)}}{{.ImportPath}} {{if .Module}}{{.Module.Dir}}{{else}}{{.Dir}}{{end}}{{end}}' ./... | grep -v /vendor/ | ||
} | ||
|
||
build_all() { | ||
# Make sure everything can compile since some package may not have tests | ||
# Note: that "go build ./..." will fail if some packages have only | ||
# tests (will get "no buildable Go source files" error) so we | ||
# have to do this the hard way. | ||
list_buildable | while read -r pkg dir; do | ||
echo '*** go build' "$pkg" | ||
buildmode=archive | ||
if [[ "$(go list -f '{{.Name}}')" == "main" ]]; then | ||
# plugin works even when a "main" function is missing. | ||
buildmode=plugin | ||
fi | ||
( cd "$dir"; go build -buildmode=$buildmode -o /dev/null "$pkg") | ||
done | ||
} | ||
|
||
build_all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
before="$1" | ||
after="$2" | ||
|
||
parse() { | ||
sed -n \ | ||
-e 's/ *\t */\t/g' \ | ||
-e '/^Benchmark/p' | | ||
column -s' ' --json \ | ||
--table-columns name,count,time,rate \ | ||
--table-name "results" | | ||
jq '.results[] | {name: .name, time: (.time | rtrimstr(" ns/op") | tonumber)}' | ||
} | ||
|
||
benchcmp "$1" "$2" | ||
|
||
echo "" | ||
echo "Result:" | ||
|
||
{ | ||
parse < "$1" | ||
parse < "$2" | ||
} | jq -e -r -s 'group_by(.name)[] | {name: .[0].name, speedup: (.[1].time / .[0].time)} | select(.speedup < 0.90) | "\(.name)\t\(.speedup)x"' | ||
|
||
if [[ $? -ne 4 ]]; then | ||
echo "" | ||
echo "FAIL" | ||
exit 1 | ||
else | ||
echo "PASS" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters