From d282ef337ad8f1af02ca96a672ce3053cc9fca79 Mon Sep 17 00:00:00 2001 From: Xing Xing Date: Sun, 29 Dec 2013 17:09:06 +0800 Subject: [PATCH] benchmark for encoding/decoding --- worker/agent.go | 5 +++++ worker/inpack_test.go | 11 +++++++++++ worker/outpack_test.go | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/worker/agent.go b/worker/agent.go index 76fbbde..b736b0a 100644 --- a/worker/agent.go +++ b/worker/agent.go @@ -39,6 +39,11 @@ func (a *agent) Connect() (err error) { } func (a *agent) work() { + defer func() { + if err := recover(); err != nil { + a.worker.err(err.(error)) + } + }() var inpack *inPack var l int var err error diff --git a/worker/inpack_test.go b/worker/inpack_test.go index b1c099f..f852a04 100644 --- a/worker/inpack_test.go +++ b/worker/inpack_test.go @@ -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) + } + } + } +} diff --git a/worker/outpack_test.go b/worker/outpack_test.go index a377445..6ae9423 100644 --- a/worker/outpack_test.go +++ b/worker/outpack_test.go @@ -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() + } + } +}