Skip to main content

README.md

1# gotools
3gotools is a collection of command-line utilities for working with Go.
5## gobench
7`gobench` automated running Go benchmarks across your current working tree and a base Git branch (usually `main`).
8It alternates benchmark runs to minimise system noise, and pipes the output into `benchstat` for comparison.
9This allows you to see the impact of your unmerged changes.
11### Installation
13`gobench` requires `benchstat` to be installed:
15```console
16$ go install golang.org/x/perf/cmd/benchstat@latest
17```
19Then install `gobench`:
21```console
22$ go install alexwlchan.net/projects/gotools/cmd/gobench@latest
23```
25### Usage and flags
27Run `gobench` and pass arguments you'd pass to `go test` to choose which benchmark to run.
28For example:
30```console
31$ gobench ./control/controlapi -bench=BenchmarkDevices
32```
34There are optional flags to control the `gobench` behaviour:
36* `-base` (default `main`) -- set the base Git branch or commit to compare against
37* `-samples` (default `6`) -- the numebr of alternating sample rounds to run
38* `-no-sync` (default `false`) -- skip copying dirty/untracked working tree files to the base worktree
40### Demo: measuring an optimisation
421. Check out this repo at `main`.
432. Create a new feature branch:
45 ```console
46 $ git checkout -b fib-faster
47 ```
493. In `example/fib/fib_test.go`, replace `FibRecursive(20)` with `FibIterative(20)`.
504. Commit your changes.
515. Run `gobench` to measure the performance impact:
53 ```console
54 $ go run ./cmd/gobench ./example/fib -bench=BenchmarkFib
55 ```
57## License
59This project is shared under the [MIT license](./LICENSE).