Running benchmarks
Go tooling runs unit tests before running benchmarks -- there is no point in benchmarking failing code.
How to do it...
- Use the
go test -bench=<regexp>
tool. To run all benchmarks, use the following command:go test -bench=.
- Enter a benchmark regular expression if you want to run a subset of the benchmarks. The following only runs benchmarks containing
1000
in their names:go test -bench=1000 goos: linux goarch: amd64 pkg: github.com/PacktPublishing/Go-Recipes-for-Developers/src/chp17/sorting/sort cpu: AMD Ryzen 5 7530U with Radeon Graphics BenchmarkSort1000Ascending-12 9753 105997 ns/op BenchmarkSort1000Descending-12 9813 105192 ns/op PASS