diff --git a/README.md b/README.md index 204279e..9e4b9b1 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,10 @@ result.Raw // holds the raw json ## Performance -Benchmarks of GJSON alongside [encoding/json](https://golang.org/pkg/encoding/json/), [ffjson](https://github.com/pquerna/ffjson), and [EasyJSON](https://github.com/mailru/easyjson). +Benchmarks of GJSON alongside [encoding/json](https://golang.org/pkg/encoding/json/), +[ffjson](https://github.com/pquerna/ffjson), +[EasyJSON](https://github.com/mailru/easyjson), +and [jsonparser](https://github.com/buger/jsonparser) ``` BenchmarkGJSONGet-8 3000000 440 ns/op 0 B/op 0 allocs/op @@ -109,9 +112,10 @@ 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 ``` -The JSON document used was: +JSON document used: ```json { diff --git a/gjson_test.go b/gjson_test.go index e652e5a..1aec401 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -10,6 +10,7 @@ import ( "testing" "time" + "github.com/buger/jsonparser" "github.com/mailru/easyjson/jlexer" fflib "github.com/pquerna/ffjson/fflib/v1" ) @@ -491,3 +492,22 @@ func BenchmarkEasyJSONLexer(t *testing.B) { } t.N *= len(benchPaths) // because we are running against 3 paths } + +func BenchmarkJSONParserGet(t *testing.B) { + data := []byte(exampleJSON) + keys := make([][]string, 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") + } + } + } + t.N *= len(benchPaths) // because we are running against 3 paths +}