forked from go-faster/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdec_skip_bench_test.go
52 lines (49 loc) · 973 Bytes
/
dec_skip_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package jx
import (
"testing"
)
type TestResp struct {
Code uint64
}
func BenchmarkSkip(b *testing.B) {
input := []byte(`
{
"_shards":{
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits":{
"total" : 1,
"hits" : [
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_source" : {
"user" : "kimchy",
"postDate" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
}
]
},
"code": 200
}`)
for n := 0; n < b.N; n++ {
result := TestResp{}
iter := DecodeBytes(input)
if err := iter.ObjBytes(func(i *Decoder, key []byte) error {
switch string(key) {
case "code":
v, err := iter.UInt64()
result.Code = v
return err
default:
return iter.Skip()
}
}); err != nil {
b.Fatal(err)
}
}
}