File: coarsetime_test.go

package info (click to toggle)
golang-github-valyala-fasthttp 1%3A1.59.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: makefile: 34
file content (37 lines) | stat: -rw-r--r-- 638 bytes parent folder | download | duplicates (2)
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")
	}
}