Home

Awesome

JSONPath Benchmark

Benchmark JSONPath

I benchmarked two JSONPaths using several libraries for the Go language. Results can be viewed through Github actions.

The focus of the measurement is the cost per job for a task that involves a significant amount of looping after all the initial preparations are complete.

There were notable performance differences. However, if the number of queries is limited, there will not be a significant variation between any of them.

Additionally, the results may vary depending on the input data. Therefore, this benchmark should be considered for informational purposes only and re-evaluated at regular intervals.

Comparing across all libraries

JSONPath : $.store.book[0].price

The following is the outcome of a JSONPath that was processed by all libraries. The library "oliveagle/JsonPath" performed the fastest, while my own library placed second.

goos: linux
goarch: amd64
pkg: github.com/AsaiYusuke/jsonpath_benchmark
cpu: AMD EPYC 7763 64-Core Processor                
Benchmark1_oliveagle_JsonPath-4          	18734323	        66.29 ns/op	       0 B/op	       0 allocs/op
Benchmark1_AsaiYusuke_JSONPath-4         	 9823591	       121.5 ns/op	      24 B/op	       2 allocs/op
Benchmark1_ohler55_OjG_jp-4              	 3013638	       398.2 ns/op	    1040 B/op	       2 allocs/op
Benchmark1_PaesslerAG_JSONPath-4         	 2722719	       438.5 ns/op	     208 B/op	       7 allocs/op
Benchmark1_vmware_labs_YAML_JSONPath-4   	 1373034	       876.8 ns/op	     400 B/op	      25 allocs/op
Benchmark1_bhmj_JSON_Slice-4             	  836502	      1435 ns/op	      24 B/op	       1 allocs/op
Benchmark1_Spyzhov_Abstract_JSON-4       	  602800	      1967 ns/op	     760 B/op	      35 allocs/op
PASS
ok  	github.com/AsaiYusuke/jsonpath_benchmark	10.395s

Comparing with a slightly complex syntax

JSONPath : $..book[?(@.price > $.store.bicycle.price)]

Among the limited number of libraries capable of handling complex syntax, my library performed the fastest.

goos: linux
goarch: amd64
pkg: github.com/AsaiYusuke/jsonpath_benchmark
cpu: AMD EPYC 7763 64-Core Processor                
Benchmark2_AsaiYusuke_JSONPath-4         	  672276	      1805 ns/op	     240 B/op	       9 allocs/op
Benchmark2_ohler55_OjG_jp-4              	  313886	      3802 ns/op	    5368 B/op	      25 allocs/op
Benchmark2_vmware_labs_YAML_JSONPath-4   	  231561	      4911 ns/op	    4528 B/op	     141 allocs/op
Benchmark2_bhmj_JSON_Slice-4             	   70189	     16745 ns/op	    1816 B/op	      43 allocs/op
Benchmark2_Spyzhov_Abstract_JSON-4       	   61666	     19474 ns/op	    7160 B/op	     279 allocs/op
PASS
ok  	github.com/AsaiYusuke/jsonpath_benchmark	6.413s