aboutsummaryrefslogtreecommitdiff
path: root/src/testing/benchmark.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2020-11-02 08:48:23 -0500
committerAustin Clements <austin@google.com>2020-11-07 22:38:01 +0000
commitafe7c8d0b25f26f0abd749ca52c7e1e7dfdee8cb (patch)
treefca642ba51085c3ebd77e54d2cd8d56b7e11418b /src/testing/benchmark.go
parent5e371e0f93c5618a36f66afdd9c6047a5955c101 (diff)
downloadgo-afe7c8d0b25f26f0abd749ca52c7e1e7dfdee8cb.tar.xz
testing: increase benchmark output to four significant figures
Currently, the benchmark output from the testing package prints small values with three significant figures. This means it can only distinguish 1 part in 100, or a 1% error, which can be enough to throw off further analysis of the output. This CL increases it to four significant figures. For time values, at least, anything beyond four significant figures is almost certainly noise. Fixes #34626. Change-Id: I3bcf305427130026276e6a4c78167989319f280c Reviewed-on: https://go-review.googlesource.com/c/go/+/267102 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/testing/benchmark.go')
-rw-r--r--src/testing/benchmark.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go
index 1b81ec3a2d..a8f75e9712 100644
--- a/src/testing/benchmark.go
+++ b/src/testing/benchmark.go
@@ -451,23 +451,27 @@ func (r BenchmarkResult) String() string {
func prettyPrint(w io.Writer, x float64, unit string) {
// Print all numbers with 10 places before the decimal point
- // and small numbers with three sig figs.
+ // and small numbers with four sig figs. Field widths are
+ // chosen to fit the whole part in 10 places while aligning
+ // the decimal point of all fractional formats.
var format string
switch y := math.Abs(x); {
- case y == 0 || y >= 99.95:
+ case y == 0 || y >= 999.95:
format = "%10.0f %s"
- case y >= 9.995:
+ case y >= 99.995:
format = "%12.1f %s"
- case y >= 0.9995:
+ case y >= 9.9995:
format = "%13.2f %s"
- case y >= 0.09995:
+ case y >= 0.99995:
format = "%14.3f %s"
- case y >= 0.009995:
+ case y >= 0.099995:
format = "%15.4f %s"
- case y >= 0.0009995:
+ case y >= 0.0099995:
format = "%16.5f %s"
- default:
+ case y >= 0.00099995:
format = "%17.6f %s"
+ default:
+ format = "%18.7f %s"
}
fmt.Fprintf(w, format, x, unit)
}