github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/fasttime/time_fast_test.go (about) 1 // Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package fasttime_test 4 5 import ( 6 "github.com/TeaOSLab/EdgeNode/internal/utils/fasttime" 7 timeutil "github.com/iwind/TeaGo/utils/time" 8 "testing" 9 "time" 10 ) 11 12 func TestFastTime_Unix(t *testing.T) { 13 for i := 0; i < 5; i++ { 14 var now = fasttime.Now() 15 t.Log(now.Unix(), now.UnixMilli(), "real:", time.Now().Unix()) 16 time.Sleep(1 * time.Second) 17 } 18 } 19 20 func TestFastTime_UnixMilli(t *testing.T) { 21 t.Log(fasttime.Now().UnixMilliString()) 22 } 23 24 func TestFastTime_UnixFloor(t *testing.T) { 25 var now = fasttime.Now() 26 27 var timestamp = time.Now().Unix() 28 t.Log("floor 60:", timestamp, now.UnixFloor(60), timeutil.FormatTime("Y-m-d H:i:s", now.UnixFloor(60))) 29 t.Log("ceil 60:", timestamp, now.UnixCell(60), timeutil.FormatTime("Y-m-d H:i:s", now.UnixCell(60))) 30 t.Log("floor 300:", timestamp, now.UnixFloor(300), timeutil.FormatTime("Y-m-d H:i:s", now.UnixFloor(300))) 31 t.Log("next minute:", now.UnixNextMinute(), timeutil.FormatTime("Y-m-d H:i:s", now.UnixNextMinute())) 32 t.Log("day:", now.Ymd()) 33 t.Log("round 5 minute:", now.Round5Hi()) 34 } 35 36 func TestFastTime_Format(t *testing.T) { 37 var now = fasttime.Now() 38 t.Log(now.Format("Y-m-d H:i:s")) 39 } 40 41 func TestFastTime_Hour(t *testing.T) { 42 var now = fasttime.Now() 43 t.Log(now.Hour()) 44 } 45 46 func BenchmarkNewFastTime(b *testing.B) { 47 b.RunParallel(func(pb *testing.PB) { 48 for pb.Next() { 49 var now = fasttime.Now() 50 _ = now.Ymd() 51 } 52 }) 53 } 54 55 func BenchmarkNewFastTime_Raw(b *testing.B) { 56 b.RunParallel(func(pb *testing.PB) { 57 for pb.Next() { 58 var now = time.Now() 59 _ = timeutil.Format("Ymd", now) 60 } 61 }) 62 }