-
Notifications
You must be signed in to change notification settings - Fork 4
/
bit_test.go
68 lines (60 loc) · 1.32 KB
/
bit_test.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import "testing"
// Package level variables to ensure compiler doesn't optimize away benchmark
var (
_ignored1 bool
_ignored2 bool
_ignored3 bool
_ignored4 bool
)
const (
check1 = 1 << iota
check2
check3
check4
)
func BenchmarkBitCheckInt(b *testing.B) {
for i := 0; i < b.N; i++ {
v := int(i)
_ignored1 = (v & check1) != 0
_ignored2 = (v & check2) != 0
_ignored3 = (v & check3) != 0
_ignored4 = (v & check4) != 0
}
}
func BenchmarkBitCheckUint8(b *testing.B) {
for i := 0; i < b.N; i++ {
v := uint8(i)
_ignored1 = (v & check1) != 0
_ignored2 = (v & check2) != 0
_ignored3 = (v & check3) != 0
_ignored4 = (v & check4) != 0
}
}
func BenchmarkBitCheckUint16(b *testing.B) {
for i := 0; i < b.N; i++ {
v := uint16(i)
_ignored1 = (v & check1) != 0
_ignored2 = (v & check2) != 0
_ignored3 = (v & check3) != 0
_ignored4 = (v & check4) != 0
}
}
func BenchmarkBitCheckUint32(b *testing.B) {
for i := 0; i < b.N; i++ {
v := uint32(i)
_ignored1 = (v & check1) != 0
_ignored2 = (v & check2) != 0
_ignored3 = (v & check3) != 0
_ignored4 = (v & check4) != 0
}
}
func BenchmarkBitCheckUint64(b *testing.B) {
for i := 0; i < b.N; i++ {
v := uint64(i)
_ignored1 = (v & check1) != 0
_ignored2 = (v & check2) != 0
_ignored3 = (v & check3) != 0
_ignored4 = (v & check4) != 0
}
}