mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
jce: optimize JceWriter_WriteMap.
name old time/op new time/op delta JceWriter_WriteMap-8 4.09µs ± 3% 2.44µs ± 1% -40.39% (p=0.000 n=10+8) name old speed new speed delta JceWriter_WriteMap-8 22.8MB/s ± 3% 38.2MB/s ± 1% +67.73% (p=0.000 n=10+8) name old alloc/op new alloc/op delta JceWriter_WriteMap-8 2.34kB ± 0% 1.30kB ± 0% -44.37% (p=0.000 n=10+10) name old allocs/op new allocs/op delta JceWriter_WriteMap-8 52.0 ± 0% 30.0 ± 0% -42.31% (p=0.000 n=10+10)
This commit is contained in:
parent
53ac47950c
commit
7bed7a3657
@ -160,11 +160,11 @@ func (w *JceWriter) WriteMap(m interface{}, tag int) {
|
||||
return
|
||||
}
|
||||
w.writeHead(8, tag)
|
||||
w.WriteInt32(int32(len(va.MapKeys())), 0)
|
||||
for _, k := range va.MapKeys() {
|
||||
v := va.MapIndex(k)
|
||||
w.WriteObject(k.Interface(), 0)
|
||||
w.WriteObject(v.Interface(), 1)
|
||||
w.WriteInt32(int32(va.Len()), 0)
|
||||
iter := va.MapRange()
|
||||
for iter.Next() {
|
||||
w.WriteObject(iter.Key().Interface(), 0)
|
||||
w.WriteObject(iter.Value().Interface(), 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
16
binary/jce/writer_test.go
Normal file
16
binary/jce/writer_test.go
Normal file
@ -0,0 +1,16 @@
|
||||
package jce
|
||||
|
||||
import "testing"
|
||||
|
||||
var globalBytes []byte
|
||||
|
||||
func BenchmarkJceWriter_WriteMap(b *testing.B) {
|
||||
var x = globalBytes
|
||||
for i := 0; i < b.N; i++ {
|
||||
w := NewJceWriter()
|
||||
w.WriteMap(req.Map, 0)
|
||||
x = w.Bytes()
|
||||
}
|
||||
globalBytes = x
|
||||
b.SetBytes(int64(len(globalBytes)))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user