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:
parent
2dd9727a6a
commit
4a777539be
26
binary/protobuf_test.go
Normal file
26
binary/protobuf_test.go
Normal 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)
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user