-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmembuffer_test.go
More file actions
57 lines (53 loc) · 1.03 KB
/
membuffer_test.go
File metadata and controls
57 lines (53 loc) · 1.03 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
package pkg
import (
"strconv"
"testing"
)
func BenchmarkMembufWriteVaruint(b *testing.B) {
//b.Skip()
bw := NewBytesWriter(10000000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
bw.Reset()
for j := 0; j < 1000000; j++ {
bw.WriteUvarint(uint64(j))
}
}
}
func BenchmarkMembufReadVaruintExp(b *testing.B) {
bw := BytesWriter{}
val := uint64(1)
for j := 0; j < 63; j++ {
bw.WriteUvarint(val)
val *= 2
}
b.ResetTimer()
br := BytesReader{buf: bw.buf}
for i := 0; i < b.N; i++ {
br.byteIndex = 0
checkVal := uint64(1)
for j := 0; j < 63; j++ {
val, err := br.ReadUvarint()
if val != checkVal || err != nil {
panic(nil)
}
checkVal *= 2
}
}
}
func BenchmarkMembufWriteVaruintSizes(b *testing.B) {
for size := 1; size <= 9; size++ {
val := uint64((1 << (size * 7)) - 1)
b.Run(
strconv.Itoa(size), func(b *testing.B) {
bw := BytesWriter{buf: make([]byte, 0, 1000)}
for i := 0; i < b.N; i++ {
bw.Reset()
for j := 0; j < 1000; j++ {
bw.WriteUvarint(val)
}
}
},
)
}
}