Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 69 additions & 89 deletions benchmark/README.md

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions benchmark/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ go 1.17
require (
github.com/PaesslerAG/jsonpath v0.1.1
github.com/bhmj/jsonslice v1.1.2
github.com/evilmonkeyinc/jsonpath v0.7.0
github.com/evilmonkeyinc/jsonpath v0.7.2
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852
github.com/spyzhov/ajson v0.7.0
github.com/stretchr/testify v1.7.0
)

require (
github.com/PaesslerAG/gval v1.0.0 // indirect
github.com/bhmj/xpression v0.9.1 // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
5 changes: 2 additions & 3 deletions benchmark/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github.com/bhmj/xpression v0.9.1 h1:N7bX/nWx9oFi/zsiMTx2ehoRApTDAWdQadq/5o2wMGk=
github.com/bhmj/xpression v0.9.1/go.mod h1:j9oYmEXJjeL9mrgW1+ZDBKJXnbupsCPGhlO9J5YhS1Q=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/evilmonkeyinc/jsonpath v0.7.0 h1:jHar8KiQNNhobwKpftn5SzqaVGbGbNb+pWm+BaRQiQw=
github.com/evilmonkeyinc/jsonpath v0.7.0/go.mod h1:exI6Yme6vucFk2m/1iVtxPaHGI17Dy9uWfsqbJ4iGHM=
github.com/evilmonkeyinc/jsonpath v0.7.2 h1:QfnIN8jFo3JOQNLkwhuAg8uPJbJz4NcCV+LRPCLLuoQ=
github.com/evilmonkeyinc/jsonpath v0.7.2/go.mod h1:exI6Yme6vucFk2m/1iVtxPaHGI17Dy9uWfsqbJ4iGHM=
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 h1:Yl0tPBa8QPjGmesFh1D0rDy+q1Twx6FyU7VWHi8wZbI=
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852/go.mod h1:eqOVx5Vwu4gd2mmMZvVZsgIqNSaW3xxRThUJ0k/TPk4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -20,7 +20,6 @@ github.com/spyzhov/ajson v0.7.0/go.mod h1:63V+CGM6f1Bu/p4nLIN8885ojBdt88TbLoSFzy
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
66 changes: 55 additions & 11 deletions jsonpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

func Benchmark_Selector(b *testing.B) {

selectors := []string{
"$.store.book[*].author",
"$..author",
Expand All @@ -25,17 +24,62 @@ func Benchmark_Selector(b *testing.B) {
"$..*",
}

for _, selector := range selectors {
b.Run(fmt.Sprintf("%s", selector), func(b *testing.B) {
var err error
for i := 0; i < b.N; i++ {
_, err = QueryString(selector, sampleDataString)
if err != nil {
b.Error()
b.Run("QueryString", func(b *testing.B) {
for _, selector := range selectors {
b.Run(fmt.Sprintf("%s", selector), func(b *testing.B) {
var err error
for i := 0; i < b.N; i++ {
_, err = QueryString(selector, sampleDataString)
if err != nil {
b.Error()
}
}
}
})
}
})
}
})

compiledSelectors := make([]*Selector, 0)
b.Run("Compile", func(b *testing.B) {
for _, selector := range selectors {
b.Run(fmt.Sprintf("%s", selector), func(b *testing.B) {
var err error
var compiled *Selector
for i := 0; i < b.N; i++ {
compiled, err = Compile(selector)
if err != nil {
b.Error()
}
}
compiledSelectors = append(compiledSelectors, compiled)
})
}
})

b.Run("Selector.QueryString", func(b *testing.B) {
for _, selector := range compiledSelectors {
b.Run(fmt.Sprintf("%s", selector.selector), func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := selector.QueryString(sampleDataString)
if err != nil {
b.Error()
}
}
})
}
})

b.Run("Selector.Query", func(b *testing.B) {
for _, selector := range compiledSelectors {
b.Run(fmt.Sprintf("%s", selector.selector), func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := selector.Query(sampleDataObject)
if err != nil {
b.Error()
}
}
})
}
})
}

// Tests designed after the examples in the specification document
Expand Down
59 changes: 31 additions & 28 deletions token/current_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,42 @@ func Test_CurrentToken_Type(t *testing.T) {
assert.Equal(t, "current", (&currentToken{}).Type())
}

func Test_CurrentToken_Apply(t *testing.T) {

tests := []*tokenTest{
{
token: &currentToken{},
input: input{
current: map[string]interface{}{
"name": "first",
},
var currentTests = []*tokenTest{
{
token: &currentToken{},
input: input{
current: map[string]interface{}{
"name": "first",
},
expected: expected{
value: map[string]interface{}{
"name": "first",
},
},
expected: expected{
value: map[string]interface{}{
"name": "first",
},
},
{
token: &currentToken{},
input: input{
current: map[string]interface{}{
"name": "first",
},
tokens: []Token{
&keyToken{
key: "name",
},
},
},
{
token: &currentToken{},
input: input{
current: map[string]interface{}{
"name": "first",
},
expected: expected{
value: "first",
tokens: []Token{
&keyToken{
key: "name",
},
},
},
}
expected: expected{
value: "first",
},
},
}

func Test_CurrentToken_Apply(t *testing.T) {
batchTokenTests(t, currentTests)
}

batchTokenTests(t, tests)
func Benchmark_CurrentToken_Apply(b *testing.B) {
batchTokenBenchmarks(b, currentTests)
}
83 changes: 43 additions & 40 deletions token/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,49 +72,52 @@ func Test_ExpressionToken_Type(t *testing.T) {
assert.Equal(t, "expression", (&expressionToken{}).Type())
}

func Test_ExpressionToken_Apply(t *testing.T) {

tests := []*tokenTest{
{
token: &expressionToken{},
input: input{},
expected: expected{
err: "invalid expression. is empty",
},
var expressionTests = []*tokenTest{
{
token: &expressionToken{},
input: input{},
expected: expected{
err: "invalid expression. is empty",
},
{
token: &expressionToken{
expression: "any",
compiledExpression: &testCompiledExpression{err: fmt.Errorf("engine error")},
},
input: input{},
expected: expected{
err: "invalid expression. engine error",
},
},
{
token: &expressionToken{
expression: "any",
compiledExpression: &testCompiledExpression{err: fmt.Errorf("engine error")},
},
{
token: &expressionToken{
expression: "any",
compiledExpression: &testCompiledExpression{response: true},
},
input: input{},
expected: expected{
value: true,
},
input: input{},
expected: expected{
err: "invalid expression. engine error",
},
{
token: &expressionToken{
expression: "any",
compiledExpression: &testCompiledExpression{response: false},
},
input: input{
tokens: []Token{&currentToken{}},
},
expected: expected{
value: false,
},
},
{
token: &expressionToken{
expression: "any",
compiledExpression: &testCompiledExpression{response: true},
},
}
input: input{},
expected: expected{
value: true,
},
},
{
token: &expressionToken{
expression: "any",
compiledExpression: &testCompiledExpression{response: false},
},
input: input{
tokens: []Token{&currentToken{}},
},
expected: expected{
value: false,
},
},
}

func Test_ExpressionToken_Apply(t *testing.T) {
batchTokenTests(t, expressionTests)
}

batchTokenTests(t, tests)
func Benchmark_ExpressionToken_Apply(b *testing.B) {
batchTokenBenchmarks(b, expressionTests)
}
Loading