github.com/hamba/timex@v1.2.1-0.20240304044353-56d3de3a9ed9/bench_test.go (about) 1 package timex_test 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/hamba/timex" 8 "github.com/hamba/timex/mono" 9 ) 10 11 func BenchmarkTimexMonoNow(b *testing.B) { 12 b.ReportAllocs() 13 b.ResetTimer() 14 b.RunParallel(func(pb *testing.PB) { 15 for pb.Next() { 16 _ = mono.Now() 17 } 18 }) 19 } 20 21 func BenchmarkTimexMonoSince(b *testing.B) { 22 start := mono.Now() 23 24 b.ReportAllocs() 25 b.ResetTimer() 26 b.RunParallel(func(pb *testing.PB) { 27 for pb.Next() { 28 _ = mono.Since(start) 29 } 30 }) 31 } 32 33 func BenchmarkTimexNow(b *testing.B) { 34 b.ReportAllocs() 35 b.ResetTimer() 36 b.RunParallel(func(pb *testing.PB) { 37 for pb.Next() { 38 _ = timex.Now() 39 } 40 }) 41 } 42 43 func BenchmarkTimexSince(b *testing.B) { 44 start := timex.Now() 45 46 b.ReportAllocs() 47 b.ResetTimer() 48 b.RunParallel(func(pb *testing.PB) { 49 for pb.Next() { 50 _ = timex.Since(start) 51 } 52 }) 53 } 54 55 func BenchmarkTimexUnix(b *testing.B) { 56 b.ReportAllocs() 57 b.ResetTimer() 58 b.RunParallel(func(pb *testing.PB) { 59 for pb.Next() { 60 _ = timex.Unix() 61 } 62 }) 63 } 64 65 func BenchmarkTimeNow(b *testing.B) { 66 b.ReportAllocs() 67 b.ResetTimer() 68 b.RunParallel(func(pb *testing.PB) { 69 for pb.Next() { 70 _ = time.Now().UnixNano() 71 } 72 }) 73 } 74 75 func BenchmarkTimeSince(b *testing.B) { 76 start := time.Now() 77 78 b.ReportAllocs() 79 b.ResetTimer() 80 b.RunParallel(func(pb *testing.PB) { 81 for pb.Next() { 82 _ = time.Since(start) 83 } 84 }) 85 } 86 87 func BenchmarkTimeUnix(b *testing.B) { 88 b.ReportAllocs() 89 b.ResetTimer() 90 b.RunParallel(func(pb *testing.PB) { 91 for pb.Next() { 92 _ = time.Now().Unix() 93 } 94 }) 95 }