wip
This commit is contained in:
20
fasttime/time.go
Normal file
20
fasttime/time.go
Normal 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
18
fasttime/time_test.go
Normal 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user