github.com/go-playground/pkg/v5@v5.29.1/time/nanotime_test.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 package timeext 5 6 import ( 7 "testing" 8 "time" 9 ) 10 11 func TestNanoTime(t *testing.T) { 12 t1 := NanoTime() 13 time.Sleep(time.Second) 14 t2 := NanoTime() 15 if t2-t1 < int64(time.Second) { 16 t.Fatalf("nanotime failed to monotonically increase, t1: %d t2: %d", t1, t2) 17 } 18 } 19 20 func BenchmarkNanoTime(b *testing.B) { 21 for i := 0; i < b.N; i++ { 22 _ = nanotime() 23 } 24 } 25 26 func BenchmarkNanoTimeUsingUnixNano(b *testing.B) { 27 for i := 0; i < b.N; i++ { 28 _ = time.Now().UnixNano() 29 } 30 }