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

testing: benchmark output is not properly aligned on large b.N values #22144

Closed
artyom opened this issue Oct 5, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@artyom
Copy link
Contributor

commented Oct 5, 2017

What did you do?

go test -run=NONE -bench=Mutex sync

What did you expect to see?

Middle column aligned.

What did you see instead?

~ ¶ go test -run=NONE -bench=Mutex sync
goos: darwin
goarch: amd64
pkg: sync
BenchmarkMutexUncontended-4      	100000000	        11.3 ns/op
BenchmarkMutex-4                 	10000000	       111 ns/op
BenchmarkMutexSlack-4            	10000000	       207 ns/op
BenchmarkMutexWork-4             	10000000	       139 ns/op
BenchmarkMutexWorkSlack-4        	 5000000	       213 ns/op
BenchmarkMutexNoSpin-4           	 2000000	       777 ns/op
BenchmarkMutexSpin-4             	  500000	      3450 ns/op
BenchmarkRWMutexUncontended-4    	30000000	        43.7 ns/op
BenchmarkRWMutexWrite100-4       	20000000	        75.2 ns/op
BenchmarkRWMutexWrite10-4        	20000000	       116 ns/op
BenchmarkRWMutexWorkWrite100-4   	10000000	       190 ns/op
BenchmarkRWMutexWorkWrite10-4    	 3000000	       416 ns/op
PASS
ok  	sync	20.832s

Note how the first line for BenchmarkMutexUncontended breaks alignment since 100M run count doesn't fit %8d format defined here:

return fmt.Sprintf("%8d\t%s%s", r.N, ns, mb)

8475832 introduced scaling of ns/op reported to 0.01ns, but for such small numbers cycle count may not fit 8 symbols, so maybe it's worth increasing width to 9-10 digits?

System details

go version go1.9.1 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/tmp/go:/Users/artyom/go"
GORACE=""
GOROOT="/Users/artyom/Library/go"
GOTOOLDIR="/Users/artyom/Library/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lb/3rk8rqs53czgb4v35w_342xc0000gn/T/go-build603696847=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOROOT/bin/go version: go version go1.9.1 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.9.1
uname -v: Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13
BuildVersion:	17A365
lldb --version: lldb-900.0.45
  Swift-4.0

@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Oct 5, 2017

@robpike

This comment has been minimized.

Copy link
Contributor

commented Oct 6, 2017

Why NeedsFix? It's a minor cosmetic issue whose solution is disproportionate to its severity.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Oct 6, 2017

It's OK with me if you just want to close it.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Oct 6, 2017

OK, closing.

The solution would require implementing a columnator in the testing package, or using something like tabwriter, but that would destroy the dependency tree for the package.

If you care about alignment, I suggest taking https://github.com/robpike/tab/blob/master/main.go plus a little work to turn the spaces into tabs before passing the text to tabwriter.

If you want numeric alignment, it's even more work though.

@robpike robpike closed this Oct 6, 2017

@golang golang locked and limited conversation to collaborators Oct 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.