1#!/bin/bash
2
3set -e
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
11    go install golang.org/x/perf/cmd/benchstat
12fi
13
14tempdir=`mktemp -d /tmp/go-toml-benchmark-XXXXXX`
15ref_tempdir="${tempdir}/ref"
16ref_benchmark="${ref_tempdir}/benchmark-`echo -n ${reference_ref}|tr -s '/' '-'`.txt"
17local_benchmark="`pwd`/benchmark-local.txt"
18
19echo "=== ${reference_ref} (${ref_tempdir})"
20git clone ${reference_git} ${ref_tempdir} >/dev/null 2>/dev/null
21pushd ${ref_tempdir} >/dev/null
22git checkout ${reference_ref} >/dev/null 2>/dev/null
23go test -bench=. -benchmem | tee ${ref_benchmark}
24popd >/dev/null
25
26echo ""
27echo "=== local"
28go test -bench=. -benchmem  | tee ${local_benchmark}
29
30echo ""
31echo "=== diff"
32benchstat -delta-test=none ${ref_benchmark} ${local_benchmark}