Example #1
0
func benchString(r testing.BenchmarkResult) string {
	nsop := r.NsPerOp()
	ns := fmt.Sprintf("%10d ns/op", nsop)
	allocs := "0"
	if r.N > 0 {
		if nsop < 100 {
			// The format specifiers here make sure that
			// the ones digits line up for all three possible formats.
			if nsop < 10 {
				ns = fmt.Sprintf("%13.2f ns/op", float64(r.T.Nanoseconds())/float64(r.N))
			} else {
				ns = fmt.Sprintf("%12.1f ns/op", float64(r.T.Nanoseconds())/float64(r.N))
			}
		}

		allocs = fmt.Sprintf("%d", r.MemAllocs/uint64(r.N))
	}

	return fmt.Sprintf("%8d\t%s\t%s allocs", r.N, ns, allocs)
}