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
|
BenchmarkJSONDecoder-8 300000 17193 ns/op 4864 B/op 184 allocs/op
|
||||||
BenchmarkFFJSONLexer-8 1500000 3773 ns/op 1024 B/op 8 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
|
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:
|
JSON document used:
|
||||||
|
|
|
@ -495,18 +495,28 @@ func BenchmarkEasyJSONLexer(t *testing.B) {
|
||||||
|
|
||||||
func BenchmarkJSONParserGet(t *testing.B) {
|
func BenchmarkJSONParserGet(t *testing.B) {
|
||||||
data := []byte(exampleJSON)
|
data := []byte(exampleJSON)
|
||||||
keys := make([][]string, len(benchPaths))
|
keys := make([][]string, 0, len(benchPaths))
|
||||||
for i := 0; i < len(benchPaths); i++ {
|
for i := 0; i < len(benchPaths); i++ {
|
||||||
keys = append(keys, strings.Split(benchPaths[i], "."))
|
keys = append(keys, strings.Split(benchPaths[i], "."))
|
||||||
}
|
}
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
for j := 0; j < len(benchPaths); j++ {
|
for j, k := range keys {
|
||||||
_, _, _, err := jsonparser.Get(data, keys[j]...)
|
if j == 1 {
|
||||||
if err != nil {
|
// "widget.image.hOffset" is a number
|
||||||
|
v, _ := jsonparser.GetInt(data, k...)
|
||||||
|
if v == 0 {
|
||||||
t.Fatal("did not find the value")
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.N *= len(benchPaths) // because we are running against 3 paths
|
t.N *= len(benchPaths) // because we are running against 3 paths
|
||||||
|
|
Loading…
Reference in New Issue
Block a user