Skip to content

AsaiYusuke/jsonpath-benchmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

211 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONPath Benchmark

Benchmark JSONPath

This project benchmarks multiple JSONPath libraries written in Go. It evaluates performance in specific scenarios and offers guidance for selecting an appropriate library.

Contents

Overview

Results are generated via GitHub Actions for consistency and automation.

The benchmark focuses on the per-operation cost after initial setup is complete. Preparatory steps, such as parsing or preloading data, are excluded from the measurements. Instead, it emphasizes scenarios with intensive looping or query execution within the main operation.

Results may vary with factors such as input structure, query complexity, and runtime environment. Treat these benchmarks as a general reference and re-evaluate them periodically.

Notes on metrics:

  • Time: ns/op (lower is better)
  • Memory: B/op (lower is better)
  • Allocations: allocs/op (lower is better)

Libraries Benchmarked

The following libraries are included in this benchmark:

Simple Query Performance

JSONPath:

$.store.book[*].price

Summary:

  • Query features:
    • root selector ($)
    • child segments (name selectors)
    • wildcard selector ([*])
  • Compatibility: 10/10 (all libraries)
  • Fastest: AsaiYusuke/JSONPath

Performance Detail:

Rank Library Time (ns/op) Memory (B/op) Allocations (allocs/op) Relative speed (fastest = 1x)
1 AsaiYusuke/JSONPath (reuse) 121.40 0 0 1.00x
2 AsaiYusuke/JSONPath 171.70 64 1 1.41x
3 Yalp/JSONPath 281.50 160 5 2.32x
4 oliveagle/JsonPath 367.10 160 5 3.02x
5 ohler55/OjG (jp) 546.30 1264 4 4.50x
6 theory/RFC 9535 JSONPath in Go 794.90 480 20 6.55x
7 PaesslerAG/JSONPath 1339.00 816 29 11.03x
8 vmware-labs/YAML JSONPath 2025.00 1240 67 16.68x
9 Spyzhov/Abstract JSON 2465.00 968 30 20.30x
10 bhmj/JSONSlice 4116.00 312 13 33.90x

Simple query benchmark (ns/op)

Complex Query Performance

JSONPath:

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

Summary:

  • Query features:
    • root selector ($)
    • descendant segment (..)
    • filter selector (?()) with comparison expression
    • path references (@ and $)
    • child segments (name selectors)
  • Compatibility: 6/10 (see Support Matrix)
  • Fastest: AsaiYusuke/JSONPath

Performance Detail:

Rank Library Time (ns/op) Memory (B/op) Allocations (allocs/op) Relative speed (fastest = 1x)
1 AsaiYusuke/JSONPath (reuse) 1146.00 80 2 1.00x
2 AsaiYusuke/JSONPath 1171.00 96 3 1.02x
3 theory/RFC 9535 JSONPath in Go 2281.00 528 33 1.99x
4 ohler55/OjG (jp) 3946.00 6200 37 3.44x
5 Spyzhov/Abstract JSON 15321.00 5464 222 13.37x
6 bhmj/JSONSlice 15586.00 1728 35 13.60x

Complex query benchmark (ns/op)

Support Matrix

Library Simple query Complex query
AsaiYusuke/JSONPath (reuse)
AsaiYusuke/JSONPath
PaesslerAG/JSONPath
bhmj/JSONSlice
ohler55/OjG (jp)
oliveagle/JsonPath
Spyzhov/Abstract JSON
theory/RFC 9535 JSONPath in Go
vmware-labs/YAML JSONPath
Yalp/JSONPath

Conclusion

This benchmark compared several popular JSONPath libraries in Go and highlighted notable performance differences. Interestingly, the simple query showed a wider performance spread than the complex one, suggesting that implementation details and variations in query syntax handling can directly impact execution speed. Therefore, a practical evaluation should consider both feature support and raw performance. For selecting a library in production, we strongly recommend running benchmarks tailored to your own datasets and query patterns.

Reproduce Locally

Benchmarks are executed in GitHub Actions for consistency. For the exact steps and current outputs, check the Actions tab and the workflow logs. If you prefer to run locally, follow the same sequence defined in the workflow file (see .github/workflows/build.yml).

License

This project is distributed under the terms of the MIT License. See LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •