• Austin Clements's avatar
    testing: fix fractional ns/op printing · 1257d050
    Austin Clements authored
    CL 166717 changed the way ns/op benchmark results were printed and
    inadvertently rounded all ns/op results down to an integer, even if
    they were small enough to print with digits after the decimal place.
    For example, prior to this change, we got output like
    
        BenchmarkFast-8       380491575	 3.12 ns/op
    
    CL 166717 changed this to
    
        BenchmarkFast-8       380491575      3.00 ns/op
    
    This had the further side-effect that ns/op values between 0 and 1
    would not be printed at all because they would be rounded down to 0.
    
    This CL fixes this by always recomputing the float64 value of ns/op
    instead of using the int64 truncation from BenchmarkResult.NsPerOp.
    
    Fixes #30997. Fixes #31005.
    
    Change-Id: I21f73b9d5cc5ad41e7ff535675d07ca00051ecd7
    Reviewed-on: https://go-review.googlesource.com/c/go/+/168937Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
    1257d050
benchmark.go 21.5 KB