Skip to content

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

@artyom

Description

@artyom

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions