-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
68 lines (61 loc) · 1.16 KB
/
Copy pathbenchmark_test.go
File metadata and controls
68 lines (61 loc) · 1.16 KB
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 binp
import (
"encoding/binary"
"testing"
)
func BenchmarkEncodingBinaryPut(b *testing.B) {
bs := make([]byte, 8)
for i := 0; i < b.N; i++ {
binary.BigEndian.PutUint32(bs, 31)
}
}
func BenchmarkEncodingBinaryGet(b *testing.B) {
bs := make([]byte, 8)
for i := 0; i < b.N; i++ {
binary.BigEndian.Uint32(bs)
}
}
func BenchmarkGetB32EB(b *testing.B) {
bs := make([]byte, 16)
var x, y uint32
for i := 0; i < b.N; i++ {
x = binary.BigEndian.Uint32(bs)
y = binary.BigEndian.Uint32(bs[4:])
x = binary.BigEndian.Uint32(bs[8:])
y = binary.BigEndian.Uint32(bs[12:])
}
_, _ = x, y
}
func BenchmarkGetB32(b *testing.B) {
bs := make([]byte, 16)
var x, y uint32
for i := 0; i < b.N; i++ {
p := NewParser(bs)
p.B32(&x).B32(&y)
p.B32(&x).B32(&y)
}
}
func BenchmarkGetN32(b *testing.B) {
bs := make([]byte, 16)
var x, y uint32
for i := 0; i < b.N; i++ {
p := NewParser(bs)
p.N32(&x).N32(&y)
p.N32(&x).N32(&y)
}
}
func BenchmarkGetByte(b *testing.B) {
bs := make([]byte, 8)
var x uint8
for i := 0; i < b.N; i++ {
p := NewParser(bs)
p.Byte(&x)
p.Byte(&x)
p.Byte(&x)
p.Byte(&x)
p.Byte(&x)
p.Byte(&x)
p.Byte(&x)
p.Byte(&x)
}
}