aboutsummaryrefslogtreecommitdiff
path: root/coarsetime_test.go
blob: b2f2334ee34fde92ec69f1841f52c89294efdd33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package fasthttp

import (
	"sync/atomic"
	"testing"
	"time"
)

func BenchmarkCoarseTimeNow(b *testing.B) {
	var zeroTimeCount uint64
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			t := CoarseTimeNow()
			if t.IsZero() {
				atomic.AddUint64(&zeroTimeCount, 1)
			}
		}
	})
	if zeroTimeCount > 0 {
		b.Fatalf("zeroTimeCount must be zero")
	}
}

func BenchmarkTimeNow(b *testing.B) {
	var zeroTimeCount uint64
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			t := time.Now()
			if t.IsZero() {
				atomic.AddUint64(&zeroTimeCount, 1)
			}
		}
	})
	if zeroTimeCount > 0 {
		b.Fatalf("zeroTimeCount must be zero")
	}
}