added jsonparser benchmark

This commit is contained in:
Josh Baker 2016-08-11 10:53:50 -07:00
parent a4005bcf0f
commit 9a63765fe5
2 changed files with 26 additions and 2 deletions

View File

@ -100,7 +100,10 @@ result.Raw // holds the raw json
## Performance ## 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 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 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
``` ```
The JSON document used was: JSON document used:
```json ```json
{ {

View File

@ -10,6 +10,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/buger/jsonparser"
"github.com/mailru/easyjson/jlexer" "github.com/mailru/easyjson/jlexer"
fflib "github.com/pquerna/ffjson/fflib/v1" 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 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
}