summaryrefslogtreecommitdiff
path: root/util/fasttime_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'util/fasttime_test.go')
-rw-r--r--util/fasttime_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/util/fasttime_test.go b/util/fasttime_test.go
index c7d86821..c8ff0e13 100644
--- a/util/fasttime_test.go
+++ b/util/fasttime_test.go
@@ -1 +1,47 @@
package util
+
+import (
+ "github.com/stretchr/testify/assert"
+ "testing"
+ "time"
+)
+
+func TestFTime_UnixNano(t *testing.T) {
+ ft := NewFastTime(time.Millisecond)
+ defer ft.Stop()
+
+ var d int64
+
+ d = time.Now().UnixNano() - ft.UnixNano()
+
+ assert.True(t, d >= 0)
+ assert.True(t, d <= int64(time.Millisecond*2))
+
+ time.Sleep(time.Millisecond * 100)
+ d = time.Now().UnixNano() - ft.UnixNano()
+
+ assert.True(t, d >= 0)
+ assert.True(t, d <= int64(time.Millisecond*2))
+}
+
+func Benchmark_FastTime(b *testing.B) {
+ ft := NewFastTime(time.Microsecond)
+ defer ft.Stop()
+
+ b.ReportAllocs()
+
+ for n := 0; n < b.N; n++ {
+ _ = ft.UnixNano()
+ }
+}
+
+func Benchmark_Time(b *testing.B) {
+ ft := NewFastTime(time.Microsecond)
+ defer ft.Stop()
+
+ b.ReportAllocs()
+
+ for n := 0; n < b.N; n++ {
+ _ = time.Now().UnixNano()
+ }
+}