This might be weird, but it seems like my benchmarks get their time units messed up and I cannot find any info online about it. The benchmarks that took shorter than a second are treated like they took shorter than a nanosecond.
Here's what I'm experiencing:
import (
"testing"
"time"
)
func BenchmarkSleeps130Ms(b *testing.B) {
time.Sleep(130 * time.Millisecond)
}
func BenchmarkSleeps1300Ms(b *testing.B) {
time.Sleep(1300 * time.Millisecond)
}
I've run go test -bench=. -benchmem on my Linux/amd64 machine:
- using go 1.20.6 in my distro's repository,
- using go 1.20.6 Docker image,
- using go 1.18.10 Docker image.
Additionally, I've also run in the cloud (on Gitpod), using go 1.20.6 provided in the default image.
All four of the times the output looked similar to this:
BenchmarkSleeps130Ms-4 1000000000 0.1301 ns/op 0 B/op 0 allocs/op
BenchmarkSleeps1300Ms-4 1 1300140266 ns/op 80 B/op 1 allocs/op
PASS
Not only is here a millisecond smaller than a nanosecond, the loop count and allocation totals are also botched.
What am I doing wrong?