Closed nyh closed 3 years ago
Unfortunately, our code just prints these time.Duration
objects using the default formatting (%v
) and this has some fixed logic on how to print things - see https://github.com/golang/go/blob/2bbb57c9d4/src/time/time.go#L700-L703. In particular, durations smaller than one milliseconds are shows as microseconds with 3 digits after the decimal points, and durations between 1ms and 1s are shown as ms with 6 digits after the decimal point, and durations more than 1s are shown with 9 digits after the decimal point! This is exactly what we see in the output above, and is extremely ugly.
See also https://stackoverflow.com/questions/58414820/limiting-significant-digits-in-formatted-durations
I think we have no choice but to write our own Duration-to-String function and use that, instead of the standard one.
When I run
I get output lines like
There is no need for this amount of precision (apparently nanoseconds) in the time measurements. It's not helpful, and makes the output line very long and inconvenient to view without deliberately starting an extremely wide terminal window.