mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
name old time/op new time/op delta JceWriter_WriteMap-8 2.34µs ± 2% 0.69µs ± 4% -70.63% (p=0.008 n=5+5) JceWriter_WriteJceStructRaw-8 1.28µs ± 1% 0.42µs ± 1% -66.86% (p=0.008 n=5+5) name old speed new speed delta JceWriter_WriteMap-8 39.7MB/s ± 2% 135.4MB/s ± 4% +240.56% (p=0.008 n=5+5) JceWriter_WriteJceStructRaw-8 82.3MB/s ± 1% 219.9MB/s ± 1% +167.32% (p=0.008 n=5+5) name old alloc/op new alloc/op delta JceWriter_WriteMap-8 1.30kB ± 0% 0.21kB ± 0% -84.05% (p=0.008 n=5+5) JceWriter_WriteJceStructRaw-8 640B ± 0% 208B ± 0% -67.50% (p=0.008 n=5+5) name old allocs/op new allocs/op delta JceWriter_WriteMap-8 30.0 ± 0% 2.0 ± 0% -93.33% (p=0.008 n=5+5) JceWriter_WriteJceStructRaw-8 15.0 ± 0% 2.0 ± 0% -86.67% (p=0.008 n=5+5)
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package jce
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var globalBytes []byte
|
|
|
|
func BenchmarkJceWriter_WriteMap(b *testing.B) {
|
|
var x = globalBytes
|
|
for i := 0; i < b.N; i++ {
|
|
w := NewJceWriter()
|
|
w.writeMapStrMapStrBytes(req.Map, 0)
|
|
x = w.Bytes()
|
|
}
|
|
globalBytes = x
|
|
b.SetBytes(int64(len(globalBytes)))
|
|
}
|
|
|
|
var reqPacket1 = &RequestPacket{
|
|
IVersion: 1,
|
|
CPacketType: 114,
|
|
IMessageType: 514,
|
|
IRequestId: 1919,
|
|
SServantName: "田所",
|
|
SFuncName: "浩二",
|
|
SBuffer: []byte{1, 1, 4, 5, 1, 4, 1, 9, 1, 9, 8, 1, 0},
|
|
ITimeout: 810,
|
|
Context: map[string]string{
|
|
"114": "514",
|
|
"1919": "810",
|
|
},
|
|
Status: map[string]string{
|
|
"野兽": "前辈",
|
|
"田所": "浩二",
|
|
},
|
|
}
|
|
|
|
func BenchmarkJceWriter_WriteJceStructRaw(b *testing.B) {
|
|
var x = globalBytes
|
|
for i := 0; i < b.N; i++ {
|
|
_ = reqPacket1.ToBytes()
|
|
}
|
|
globalBytes = x
|
|
b.SetBytes(int64(len(globalBytes)))
|
|
}
|
|
|
|
func TestJceWriter_WriteJceStructRaw(t *testing.T) {
|
|
r := NewJceReader(reqPacket1.ToBytes())
|
|
var reqPacket2 RequestPacket
|
|
reqPacket2.ReadFrom(r)
|
|
assert.Equal(t, reqPacket1, &reqPacket2)
|
|
}
|