gotools
A collection of command-line utilities for working with Go
gotools is a collection of command-line utilities for working with Go.
gobench
gobench automated running Go benchmarks across your current working tree and a base Git branch (usually main). It alternates benchmark runs to minimise system noise, and pipes the output into benchstat for comparison. This allows you to see the impact of your unmerged changes.
Installation
gobench requires benchstat to be installed:
$ go install golang.org/x/perf/cmd/benchstat@latestThen install gobench:
$ go install alexwlchan.net/projects/gotools/cmd/gobench@latestUsage and flags
Run gobench and pass arguments you’d pass to go test to choose which benchmark to run. For example:
$ gobench ./control/controlapi -bench=BenchmarkDevicesThere are optional flags to control the gobench behaviour:
-base(defaultmain) – set the base Git branch or commit to compare against-samples(default6) – the numebr of alternating sample rounds to run-no-sync(defaultfalse) – skip copying dirty/untracked working tree files to the base worktree
Demo: measuring an optimisation
Check out this repo at
main.Create a new feature branch:
$ git checkout -b fib-fasterIn
example/fib/fib_test.go, replaceFibRecursive(20)withFibIterative(20).Commit your changes.
Run
gobenchto measure the performance impact:$ go run ./cmd/gobench ./example/fib -bench=BenchmarkFib
License
This project is shared under the MIT license.