Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/perf/benchstat: support piping results to benchstat #23896

Closed
kevinburke opened this issue Feb 17, 2018 · 8 comments
Closed

x/perf/benchstat: support piping results to benchstat #23896

kevinburke opened this issue Feb 17, 2018 · 8 comments

Comments

@kevinburke
Copy link
Contributor

I just want human-readable output for the number of allocations and the time taken. Currently I write this in a Makefile:

BENCHSTAT := $(GOPATH)/bin/benchstat

$(BENCHSTAT):
	go get -u golang.org/x/perf/cmd/benchstat

bench: $(BENCHSTAT)
	tmp=$$(mktemp); go list ./... | grep -v vendor | xargs go test -benchtime=2s -bench=. -run='^$$' > "$$tmp" 2>&1 && $(BENCHSTAT) "$$tmp"

It would be simpler if you could pipe the results of go test -bench=. directly to benchstat, instead of having to send it to a file first.

@gopherbot gopherbot added this to the Unreleased milestone Feb 17, 2018
@kevinburke kevinburke changed the title x/perf/benchstat: support piping results x/perf/benchstat: support piping results to benchstat Feb 17, 2018
@davecheney
Copy link
Contributor

davecheney commented Feb 17, 2018 via email

@kevinburke
Copy link
Contributor Author

kevinburke commented Feb 17, 2018

If you run benchstat with a single file input, it prints the outputs in human readable format. Example go test -bench output:

BenchmarkUDist-4       	    1000	   1399086 ns/op
BenchmarkUDistTies-4   	     300	   4336160 ns/op

And the same file output run through benchstat:

$ benchstat benchstat.out
name         time/op
UDist-4      1.40ms ± 0%
UDistTies-4  4.34ms ± 0%

Perhaps a better solution would be add a human-readable flag to go test -bench but that seems like a more involved process.

@kevinburke
Copy link
Contributor Author

We could also add a second command, humanbench or something, that translates Go bench output into human readable format, either from a file or from stdin.

@gopherbot
Copy link

Change https://golang.org/cl/94905 mentions this issue: cmd/benchstat: Support input on stdin

@davecheney
Copy link
Contributor

davecheney commented Feb 17, 2018 via email

@rsc
Copy link
Contributor

rsc commented Feb 18, 2018

Replied on the CL; please use benchstat /dev/stdin for now. I don't think this is commonly needed enough to confuse people who just type 'benchstat'.

@kevinburke
Copy link
Contributor Author

ah, neat, I didn't know about the /dev/stdin trick!

@kevinburke
Copy link
Contributor Author

Alright, closing, fwiw I made github.com/kevinburke/humanbench to translate the benchmark results on the fly.

@golang golang locked and limited conversation to collaborators Feb 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants