-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbit_test.go
57 lines (50 loc) · 930 Bytes
/
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
package plan9
import (
"strings"
"testing"
)
func TestPstringTooLong(t *testing.T) {
tt := struct {
name string
b []byte
s string
}{
name: "string too long",
b: make([]byte, STATMAX),
s: strings.Repeat("b", STATMAX+1),
}
t.Run(tt.name, func(t *testing.T) {
defer func() { _ = recover() }()
_ = pstring(tt.b, tt.s)
t.Errorf("expecting panic for %s", tt.name)
})
}
var pbuf = []byte{0, 0, 0, 0, 0, 0, 0, 0}
func BenchmarkPBit8(b *testing.B) {
i := 0
b.SetBytes(2)
for ; i < b.N; i++ {
_ = pbit8(pbuf[:2], uint8(i))
}
}
func BenchmarkPBit16(b *testing.B) {
i := 0
b.SetBytes(2)
for ; i < b.N; i++ {
_ = pbit16(pbuf[:2], uint16(i))
}
}
func BenchmarkPBit32(b *testing.B) {
i := 0
b.SetBytes(4)
for ; i < b.N; i++ {
_ = pbit32(pbuf[:4], uint32(i))
}
}
func BenchmarkPBit64(b *testing.B) {
i := 0
b.SetBytes(8)
for ; i < b.N; i++ {
_ = pbit64(pbuf[:8], uint64(i))
}
}