forked from yuxh/gearman-go
benchmark for encoding/decoding
This commit is contained in:
parent
9f96247384
commit
d282ef337a
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user