forked from Mrs4s/MiraiGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic_test.go
46 lines (41 loc) · 897 Bytes
/
dynamic_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
package proto
import (
"math"
"testing"
)
func benchEncoderUvarint(b *testing.B, v uint64) {
e := encoder{}
for i := 0; i < b.N; i++ {
e.buf = e.buf[:0]
e.uvarint(v)
}
}
func benchEncoderSvarint(b *testing.B, v int64) {
e := encoder{}
for i := 0; i < b.N; i++ {
e.buf = e.buf[:0]
e.svarint(v)
}
}
func Benchmark_encoder_uvarint(b *testing.B) {
b.Run("short", func(b *testing.B) {
benchEncoderUvarint(b, uint64(1))
})
b.Run("medium", func(b *testing.B) {
benchEncoderUvarint(b, uint64(114514))
})
b.Run("large", func(b *testing.B) {
benchEncoderUvarint(b, math.MaxUint64)
})
}
func Benchmark_encoder_svarint(b *testing.B) {
b.Run("short", func(b *testing.B) {
benchEncoderSvarint(b, int64(1))
})
b.Run("medium", func(b *testing.B) {
benchEncoderSvarint(b, int64(114514))
})
b.Run("large", func(b *testing.B) {
benchEncoderSvarint(b, math.MaxInt64)
})
}