@@ -3,7 +3,6 @@ package jsonpath
33import (
44 "encoding/json"
55 "fmt"
6- //"golang.org/x/tools/go/types"
76 "go/token"
87 "go/types"
98 "reflect"
@@ -55,18 +54,6 @@ func init() {
5554 json .Unmarshal ([]byte (data ), & json_data )
5655}
5756
58- func Benchmark_JsonPathLookup (b * testing.B ) {
59- for n := 0 ; n < b .N ; n ++ {
60- res , err := JsonPathLookup (json_data , "$.store.book[0].price" )
61- if res_v , ok := res .(float64 ); ok != true || res_v != 8.95 {
62- b .Errorf ("$.store.book[0].price should be 8.95" )
63- }
64- if err != nil {
65- b .Errorf ("Unexpected error: %v" , err )
66- }
67- }
68- }
69-
7057func Test_jsonpath_JsonPathLookup_1 (t * testing.T ) {
7158 // key from root
7259 res , _ := JsonPathLookup (json_data , "$.expensive" )
@@ -996,7 +983,73 @@ func Test_jsonpath_num_cmp(t *testing.T) {
996983}
997984
998985func BenchmarkJsonPathLookup (b * testing.B ) {
986+ for n := 0 ; n < b .N ; n ++ {
987+ res , err := JsonPathLookup (json_data , "$.store.book[0].price" )
988+ if res_v , ok := res .(float64 ); ok != true || res_v != 8.95 {
989+ b .Errorf ("$.store.book[0].price should be 8.95" )
990+ }
991+ if err != nil {
992+ b .Errorf ("Unexpected error: %v" , err )
993+ }
994+ }
995+ }
996+
997+ func BenchmarkJsonPathLookup_0 (b * testing.B ) {
998+ for i := 0 ; i < b .N ; i ++ {
999+ JsonPathLookup (json_data , "$.expensive" )
1000+ }
1001+ }
1002+
1003+ func BenchmarkJsonPathLookup_1 (b * testing.B ) {
1004+ for i := 0 ; i < b .N ; i ++ {
1005+ JsonPathLookup (json_data , "$.store.book[0].price" )
1006+ }
1007+ }
1008+
1009+ func BenchmarkJsonPathLookup_2 (b * testing.B ) {
1010+ for i := 0 ; i < b .N ; i ++ {
1011+ JsonPathLookup (json_data , "$.store.book[-1].price" )
1012+ }
1013+ }
1014+
1015+ func BenchmarkJsonPathLookup_3 (b * testing.B ) {
1016+ for i := 0 ; i < b .N ; i ++ {
1017+ JsonPathLookup (json_data , "$.store.book[0,1].price" )
1018+ }
1019+ }
1020+
1021+ func BenchmarkJsonPathLookup_4 (b * testing.B ) {
1022+ for i := 0 ; i < b .N ; i ++ {
1023+ JsonPathLookup (json_data , "$.store.book[0:2].price" )
1024+ }
1025+ }
1026+
1027+ func BenchmarkJsonPathLookup_5 (b * testing.B ) {
1028+ for i := 0 ; i < b .N ; i ++ {
1029+ JsonPathLookup (json_data , "$.store.book[?(@.isbn)].price" )
1030+ }
1031+ }
1032+
1033+ func BenchmarkJsonPathLookup_6 (b * testing.B ) {
1034+ for i := 0 ; i < b .N ; i ++ {
1035+ JsonPathLookup (json_data , "$.store.book[?(@.price > 10)].title" )
1036+ }
1037+ }
1038+
1039+ func BenchmarkJsonPathLookup_7 (b * testing.B ) {
1040+ for i := 0 ; i < b .N ; i ++ {
1041+ JsonPathLookup (json_data , "$.store.book[?(@.price < $.expensive)].price" )
1042+ }
1043+ }
1044+
1045+ func BenchmarkJsonPathLookup_8 (b * testing.B ) {
1046+ for i := 0 ; i < b .N ; i ++ {
1047+ JsonPathLookup (json_data , "$.store.book[:].price" )
1048+ }
1049+ }
1050+
1051+ func BenchmarkJsonPathLookup_9 (b * testing.B ) {
9991052 for i := 0 ; i < b .N ; i ++ {
1000- JsonPathLookup (json_data , "$.books [?(@.price > 20 )].name " )
1053+ JsonPathLookup (json_data , "$.store.book [?(@.author == 'Nigel Rees' )].price " )
10011054 }
10021055}
0 commit comments