benchmark for encoding/decoding

This commit is contained in:
Xing Xing 2013-12-29 17:09:06 +08:00
parent 9f96247384
commit d282ef337a
3 changed files with 32 additions and 0 deletions

View File

@ -39,6 +39,11 @@ func (a *agent) Connect() (err error) {
} }
func (a *agent) work() { func (a *agent) work() {
defer func() {
if err := recover(); err != nil {
a.worker.err(err.(error))
}
}()
var inpack *inPack var inpack *inPack
var l int var l int
var err error var err error

View File

@ -60,3 +60,14 @@ func TestInPack(t *testing.T) {
} }
} }
} }
func BenchmarkDecode(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, v := range inpackcases {
_, _, err := decodeInPack([]byte(v["src"]))
if err != nil {
b.Error(err)
}
}
}
}

View File

@ -81,3 +81,19 @@ func TestOutPack(t *testing.T) {
} }
} }
} }
func BenchmarkEncode(b *testing.B) {
for i := 0; i < b.N; i++ {
for k, v := range outpackcases {
outpack := getOutPack()
outpack.dataType = k
if handle, ok := v["handle"]; ok {
outpack.handle = handle
}
if data, ok := v["data"]; ok {
outpack.data = []byte(data)
}
outpack.Encode()
}
}
}