Skip to main content

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@latest

Then install gobench:

$ go install alexwlchan.net/projects/gotools/cmd/gobench@latest

Usage 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=BenchmarkDevices

There are optional flags to control the gobench behaviour:

Demo: measuring an optimisation

  1. Check out this repo at main.

  2. Create a new feature branch:

    $ git checkout -b fib-faster
  3. In example/fib/fib_test.go, replace FibRecursive(20) with FibIterative(20).

  4. Commit your changes.

  5. Run gobench to measure the performance impact:

    $ go run ./cmd/gobench ./example/fib -bench=BenchmarkFib

License

This project is shared under the MIT license.