File: benchcmp.sh

package info (click to toggle)
golang-github-lestrrat-go-jwx 2.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,872 kB
  • sloc: sh: 222; makefile: 86; perl: 62
file content (60 lines) | stat: -rwxr-xr-x 1,158 bytes parent folder | download
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
#!/bin/bash

# ./benchcmp.sh branch1 branch2 [count]

function curbranch {
	git rev-parse --abbrev-ref HEAD 2>/dev/null
}

function curcommit {
	git log -n 1 --format=%H | cut -c 1-9
}

count=$3
if [[ -z "$count" ]]; then
	count=5
fi

if [[ ! "$count" != ^[1-9][0-9]*$ ]]; then
	echo "third argument must be a positive integer"
	exit 1
fi

set -e

tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'jwxbench')

origbranch=$(git rev-parse --abbrev-ref HEAD)
outputfiles=()
commits=()

echo "# Going to run ${count} iterations of benchmarks against $1 and $2 branches"
for branch in $1 $2
do
  cbranch=$(curbranch)
	if [[ "$branch" != "$cbranch" ]]; then
		git switch $branch
	fi

	echo "# Running benchmark against $branch..."
	output="${tmpdir}/${branch/\//-}.bench.txt"
	outputfiles+=($output)
	commits+=($(curcommit))

	pushd bench
	set -x
	go test -count=$count -bench . -benchmem | tee "$output"
	set +x
	popd
done

cbranch=$(curbranch)
if [[ "$cbranch" != "$origbranch" ]]; then
	git switch "$origbranch"
fi

echo "Benchmark comparison for:"
echo "  $1 (${commits[0]})"
echo "  $2 (${commits[1]})"
echo ""
benchstat "${outputfiles[0]}" "${outputfiles[1]}"