2020-05-14 19:01:51 +00:00
|
|
|
package fasttime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync/atomic"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkUnixTimestamp(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
var ts uint64
|
|
|
|
for pb.Next() {
|
|
|
|
ts += UnixTimestamp()
|
|
|
|
}
|
2024-02-24 00:07:51 +00:00
|
|
|
Sink.Store(ts)
|
2020-05-14 19:01:51 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTimeNowUnix(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
var ts uint64
|
|
|
|
for pb.Next() {
|
|
|
|
ts += uint64(time.Now().Unix())
|
|
|
|
}
|
2024-02-24 00:07:51 +00:00
|
|
|
Sink.Store(ts)
|
2020-05-14 19:01:51 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sink should prevent from code elimination by optimizing compiler
|
2024-02-24 00:07:51 +00:00
|
|
|
var Sink atomic.Uint64
|