forked from mirror/gjson
fixed benchmark bug with jsonparser
Big thanks to dlsspy for pointing this out.
This commit is contained in:
parent
d0d9241c76
commit
06af1af34e
|
@ -112,7 +112,7 @@ BenchmarkJSONUnmarshalStruct-8 600000 11635 ns/op 1960 B/op 69 allocs/op
|
|||
BenchmarkJSONDecoder-8 300000 17193 ns/op 4864 B/op 184 allocs/op
|
||||
BenchmarkFFJSONLexer-8 1500000 3773 ns/op 1024 B/op 8 allocs/op
|
||||
BenchmarkEasyJSONLexer-8 3000000 1134 ns/op 741 B/op 6 allocs/op
|
||||
BenchmarkJSONParserGet-8 3000000 777 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkJSONParserGet-8 3000000 596 ns/op 21 B/op 0 allocs/op
|
||||
```
|
||||
|
||||
JSON document used:
|
||||
|
|
|
@ -495,17 +495,27 @@ func BenchmarkEasyJSONLexer(t *testing.B) {
|
|||
|
||||
func BenchmarkJSONParserGet(t *testing.B) {
|
||||
data := []byte(exampleJSON)
|
||||
keys := make([][]string, len(benchPaths))
|
||||
keys := make([][]string, 0, len(benchPaths))
|
||||
for i := 0; i < len(benchPaths); i++ {
|
||||
keys = append(keys, strings.Split(benchPaths[i], "."))
|
||||
}
|
||||
t.ResetTimer()
|
||||
t.ReportAllocs()
|
||||
for i := 0; i < t.N; i++ {
|
||||
for j := 0; j < len(benchPaths); j++ {
|
||||
_, _, _, err := jsonparser.Get(data, keys[j]...)
|
||||
if err != nil {
|
||||
t.Fatal("did not find the value")
|
||||
for j, k := range keys {
|
||||
if j == 1 {
|
||||
// "widget.image.hOffset" is a number
|
||||
v, _ := jsonparser.GetInt(data, k...)
|
||||
if v == 0 {
|
||||
t.Fatal("did not find the value")
|
||||
}
|
||||
} else {
|
||||
// "widget.window.name",
|
||||
// "widget.text.onMouseUp",
|
||||
v, _ := jsonparser.GetString(data, k...)
|
||||
if v == "" {
|
||||
t.Fatal("did not find the value")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue