Skip to content

testing: benchmark results are not well aligned #8780

@gopherbot

Description

@gopherbot

by jasonhall@google.com:

What does 'go version' print?
go version go1.3 linux/amd64


What steps reproduce the problem?

1. Run a benchmark ('go test -bench=.') on a suite that has differently-lengthed
benchmark names

What happened?

Output is disjointed and difficult to scan for relative benchmark times, e.g.:

$ go test -bench=.
PASS
BenchmarkSortInt64Reflect             50          45768737 ns/op
BenchmarkSortInt64New         50          48225829 ns/op
BenchmarkSortInt64Old        100          15282155 ns/op
BenchmarkSortInt32Reflect             50          48708838 ns/op
BenchmarkSortInt32New         50          48018021 ns/op
BenchmarkSortInt32Old        100          15299048 ns/op
BenchmarkSortStructReflect            50          49120054 ns/op
BenchmarkSortStructNew        50          49305384 ns/op
BenchmarkSortStructOld       100          18308491 ns/op

It's not immediately apparent that Reflect and New are roughly the same without copying
the output and aligning the values.


What should have happened instead?

Columns line up in an easy-to-read fashion, with ns/op and iterations values
right-aligned across benchmarks.


Please provide any additional information below.

Benchmark outputs are generated using a String() method that doesn't take into account
other benchmark results being printed:
http://golang.org/src/pkg/testing/benchmark.go#L256

An alternative would be to have each BenchmarkResult provide a []byte separating fields
with a \t and using the tabwriter package to align the results, periodically Flushing
the output. We would lose the streamed output that the current behavior provides, but
the columns would be aligned for easier consumption.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions