2020-05-14 21:01:51 +02: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 01:07:51 +01:00
|
|
|
Sink.Store(ts)
|
2020-05-14 21:01:51 +02: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 01:07:51 +01:00
|
|
|
Sink.Store(ts)
|
2020-05-14 21:01:51 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sink should prevent from code elimination by optimizing compiler
|
2024-02-24 01:07:51 +01:00
|
|
|
var Sink atomic.Uint64
|