1#!/bin/bash
2
3set -ex
4
5reference_ref=${1:-master}
6reference_git=${2:-.}
7
8if ! `hash benchstat 2>/dev/null`; then
9    echo "Installing benchstat"
10    go get golang.org/x/perf/cmd/benchstat
11fi
12
13tempdir=`mktemp -d /tmp/go-toml-benchmark-XXXXXX`
14ref_tempdir="${tempdir}/ref"
15ref_benchmark="${ref_tempdir}/benchmark-`echo -n ${reference_ref}|tr -s '/' '-'`.txt"
16local_benchmark="`pwd`/benchmark-local.txt"
17
18echo "=== ${reference_ref} (${ref_tempdir})"
19git clone ${reference_git} ${ref_tempdir} >/dev/null 2>/dev/null
20pushd ${ref_tempdir} >/dev/null
21git checkout ${reference_ref} >/dev/null 2>/dev/null
22go test -bench=. -benchmem | tee ${ref_benchmark}
23cd benchmark
24go test -bench=. -benchmem | tee -a ${ref_benchmark}
25popd >/dev/null
26
27echo ""
28echo "=== local"
29go test -bench=. -benchmem  | tee ${local_benchmark}
30cd benchmark
31go test -bench=. -benchmem | tee -a ${local_benchmark}
32
33echo ""
34echo "=== diff"
35benchstat -delta-test=none ${ref_benchmark} ${local_benchmark}
36