version: 2.1 orbs: ci-go: ipfs/ci-go@0.1 commands: benchcmp: parameters: before: description: "File containing the old benchmarks." type: string after: description: "File containing the new benchmarks." type: string tolerance: description: "Tolerable slowdown (%)." type: integer default: 25 environment: BEFORE: << parameters.before >> AFTER: << parameters.after >> steps: - run: name: "Comparing benchmarks." command: | parse() { sed -n \ -e 's/ *\t */\t/g' \ -e '/^Benchmark/p' | awk 'BEGIN{print "{\"results\": ["} {print " {\"name\": \"",$1,"\", \"time\": ",$3," },"} END{print "]}"}' OFS="" ORS=" "| sed -e 's/, ]/ ]/g' | jq '.results[] | {name: .name, time: .time }' } benchcmp "$BEFORE" "$AFTER" echo "" echo "Result:" { parse < "$BEFORE" parse < "$AFTER" } | jq -e -r -s 'group_by(.name)[] | {name: .[0].name, speedup: (.[0].time / .[1].time)} | select(.speedup < (100 - << parameters.tolerance >>)/100) | "\(.name)\t\(.speedup)x"' if [[ $? -ne 4 ]]; then echo "" echo "FAIL" exit 1 else echo "PASS" fi benchmark: parameters: output: description: "File to write the results to." type: string branch: description: "Branch to benchmark." type: string default: HEAD command: description: "Benchmark command." type: string default: go test -run=NONE -bench=. ./... steps: - run: name: Check out << parameters.branch >> command: | mkdir /tmp/benchmark git --work-tree=/tmp/benchmark checkout << parameters.branch >> - run: name: "Benchmarking" command: | { << parameters.command >> } | tee << parameters.output >> working_directory: /tmp/benchmark environment: IPFS_LOGGING: critical - run: when: always name: Cleanup command: rm -rf /tmp/benchmark jobs: benchmark: parameters: tolerance: description: "Tolerable slowdown (%)." type: integer default: 25 baseline: description: "Baseline branch to which to compare (if any)." type: string default: "" command: description: "Benchmark command." type: string default: go test -run=NONE -bench=. ./... executor: ci-go/default steps: - checkout - ci-go/restore-cache - benchmark: command: << parameters.command >> branch: master output: ~/benchmark-before.txt - benchmark: command: << parameters.command >> output: ~/benchmark-after.txt - benchcmp: before: ~/benchmark-before.txt after: ~/benchmark-after.txt tolerance: << parameters.tolerance >> - when: condition: << parameters.baseline >> steps: - benchmark: command: << parameters.command >> branch: << parameters.baseline >> output: ~/benchmark-baseline.txt - benchcmp: before: ~/benchmark-baseline.txt after: ~/benchmark-after.txt tolerance: << parameters.tolerance >> - ci-go/save-cache workflows: version: 2 test: jobs: - ci-go/build - ci-go/lint - ci-go/test - benchmark: require: ci-go/test