This commit is contained in:
jdl
2024-12-08 09:45:29 +01:00
parent 55a9bf9dc3
commit 03ff1aac80
60 changed files with 3165 additions and 2 deletions

20
fasttime/time.go Normal file
View File

@@ -0,0 +1,20 @@
package fasttime
import (
"sync/atomic"
"time"
)
var _timestamp int64 = time.Now().Unix()
func init() {
go func() {
for range time.Tick(1100 * time.Millisecond) {
atomic.StoreInt64(&_timestamp, time.Now().Unix())
}
}()
}
func Now() int64 {
return atomic.LoadInt64(&_timestamp)
}

18
fasttime/time_test.go Normal file
View File

@@ -0,0 +1,18 @@
package fasttime
import (
"testing"
"time"
)
func BenchmarkNow(b *testing.B) {
for i := 0; i < b.N; i++ {
Now()
}
}
func BenchmarkTimeUnix(b *testing.B) {
for i := 0; i < b.N; i++ {
time.Now().Unix()
}
}