mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
33 lines
491 B
Go
33 lines
491 B
Go
package timex
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRelativeTime(t *testing.T) {
|
|
time.Sleep(time.Millisecond)
|
|
now := Now()
|
|
assert.True(t, now > 0)
|
|
time.Sleep(time.Millisecond)
|
|
assert.True(t, Since(now) > 0)
|
|
}
|
|
|
|
func BenchmarkTimeSince(b *testing.B) {
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
_ = time.Since(time.Now())
|
|
}
|
|
}
|
|
|
|
func BenchmarkTimexSince(b *testing.B) {
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
_ = Since(Now())
|
|
}
|
|
}
|