...
1#!/bin/bash
2
3# ./benchcmp.sh branch1 branch2 [count]
4
5function curbranch {
6 git rev-parse --abbrev-ref HEAD 2>/dev/null
7}
8
9function curcommit {
10 git log -n 1 --format=%H | cut -c 1-9
11}
12
13count=$3
14if [[ -z "$count" ]]; then
15 count=5
16fi
17
18if [[ ! "$count" != ^[1-9][0-9]*$ ]]; then
19 echo "third argument must be a positive integer"
20 exit 1
21fi
22
23set -e
24
25tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'jwxbench')
26
27origbranch=$(git rev-parse --abbrev-ref HEAD)
28outputfiles=()
29commits=()
30
31echo "# Going to run ${count} iterations of benchmarks against $1 and $2 branches"
32for branch in $1 $2
33do
34 cbranch=$(curbranch)
35 if [[ "$branch" != "$cbranch" ]]; then
36 git switch $branch
37 fi
38
39 echo "# Running benchmark against $branch..."
40 output="${tmpdir}/${branch/\//-}.bench.txt"
41 outputfiles+=($output)
42 commits+=($(curcommit))
43
44 pushd bench
45 set -x
46 go test -count=$count -bench . -benchmem | tee "$output"
47 set +x
48 popd
49done
50
51cbranch=$(curbranch)
52if [[ "$cbranch" != "$origbranch" ]]; then
53 git switch "$origbranch"
54fi
55
56echo "Benchmark comparison for:"
57echo " $1 (${commits[0]})"
58echo " $2 (${commits[1]})"
59echo ""
60benchstat "${outputfiles[0]}" "${outputfiles[1]}"
View as plain text