Reputation: 345
When I am running a benchmark on this repository (just a placeholder for any go project) using:
go test -run="^$" -bench="^BenchmarkLessorRevoke1000$" ./...
The output I am getting is this, the benchmark results are shown:
BenchmarkLessorRevoke1000-8 1033351 1141 ns/op
but also with a whole bunch of other test output. how do I make it only show the benchmarks and not the test outputs?
Upvotes: 2
Views: 235
Reputation: 1245
You can supply a dummy name to the -run
parameter of the go test
tool and providing you don't have any tests matching that name, then only the benchmarks should get ran.
You covered this with "^$"
so all good, you are also have a pattern to match a benchmarks with "^BenchmarkLessorRevoke1000$"
.
The issue is that you are running go test throughout the entire package and/or subdirectories with the ./...
.
You should specify the benchmarks that you want to run on a per package basis.
go test -run="$^" -bench="^BenchmarkLessorRevoke1000$" .
go test -run="$^" -bench="^BenchmarkLessorRevoke1000$" ./pkg1/
go test -run="$^" -bench="^BenchmarkLessorRevoke1000$" ./pkg2/
Also be mindful, if you do want to run benchmarks in mass you should do so on a per-package basis.
Running benchmarks for multiple packages will execute them concurrently, skewing your results.
Upvotes: 4