go/gobench
- 3.0 kB
- Bash
- View raw
1#!/usr/bin/env bash
3# gobench helps me compare benchmarks between a local branch and main,
4# so I can see the difference (and hopefully the improvement!).
5#
6# It runs samples in the local branch and main, then compares the
7# results using benchstat.
8#
9# == Usage ==
10#
11# Call `gobench` with the arguments you'd pass to `go test` to run
12# the benchmark. For example:
13#
14# $ gobench ./control -bench=BenchmarkServerEncode
15#
16# By default, it runs 6 samples. If you want to run more samples, set
17# the SAMPLE_COUNT environment variable. For example:
18#
19# $ SAMPLE_COUNT=12 gobench ./control -bench=BenchmarkServerEncode
20#
21# == Installation ==
22#
23# You need to install benchstat to use this script.
24#
25# $ go install golang.org/x/perf/cmd/benchstat@latest
26#
28set -o errexit
29set -o nounset
31# 1. Get the current branch and commits to test
39fi
44fi
46# 2. Create a temporary log for output. Clean it up on exit or error,
47# and restore the starting branch/commit.
51# 3. Create a temporary directory to store output
55# 4. Determine the Go binary to use.
56#
57# Prefer `./tool/go` if present (which is common in Tailscale repos);
58# fallback to `go` if not.
62fi
64# 5. Run alternating benchmarks
74 # Benchmark main
81 fi
84 # Benchmark head
91 fi
93done
97# 6. Compare results
99 echo "ERROR: benchstat is required. Install via: go install golang.org/x/perf/cmd/benchstat@latest" >&2
101fi
107popd >/dev/null