1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

test: add benchmark for (*encoder).uvarint

This commit is contained in:
wdvxdr 2021-11-07 13:28:17 +08:00
parent 2dd9727a6a
commit 4a777539be
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6

26
binary/protobuf_test.go Normal file
View File

@ -0,0 +1,26 @@
package binary
import (
"math"
"testing"
)
func benchEncoderUvarint(b *testing.B, v uint64) {
e := encoder{}
for i := 0; i < b.N; i++ {
e.Reset()
e.uvarint(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)
})
}