Skip to content

Commit

Permalink
Fix basic design, move benchmarks outside (#20)
Browse files Browse the repository at this point in the history
* fix basic design
* move benchmark results outside
  • Loading branch information
AsaiYusuke committed Jan 30, 2023
1 parent f6d259b commit cb2e5eb
Showing 1 changed file with 9 additions and 107 deletions.
116 changes: 9 additions & 107 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ func main() {

## Basic design

#### _Ease of development_
#### _Streamlined Development_

- [PEG](https://github.com/pointlander/peg) separated the JSONPath syntax analyzer from functionality itself to simplify the source.
- Equipped with a large number of unit tests to avoid bugs that lead to unexpected results.
- The JSONPath syntax analysis functionality has been separated using [PEG](https://github.com/pointlander/peg), resulting in a more simplified source code.
- Robust unit testing has been implemented to prevent bugs and ensure consistent outcomes.

#### _Ease of use_
#### _User-Friendly Interface_

- The error specification enables the library user to handle errors correctly.
- The library is equipped with a comprehensive error specification, allowing users to effectively handle any errors that may arise.

#### _Compatibility_
#### _Unwavering Compatibility_

- Adopted more of the consensus behavior from the [Christoph Burgmer's json-path-comparison](https://github.com/cburgmer/json-path-comparison).
- The library has integrated a greater level of consensus behavior from [Christoph Burgmer's json-path-comparison](https://github.com/cburgmer/json-path-comparison), ensuring seamless compatibility with related technologies.

## How to use

Expand Down Expand Up @@ -274,107 +274,9 @@ Output : [{"a":1},{"b":{"x":"hello world"}}]

## Benchmarks

I benchmarked two JSONPaths using several libraries for the Go language.
What is being measured is the cost per job for a job that loops a lot after all the prep work done.
The benchmarks for various JSONPath libraries in Go language can be compared in the following repository.

There was a performance differences.
But if the number of queries is little, there will not be a big difference between any of them.

Also, the results will vary depending on the data entered.
So this benchmark is for information only and should be re-measured at every time.

- [BenchmarkAsaiYusukeJSONPath](https://github.com/AsaiYusuke/jsonpath)
- [BenchmarkOhler55Ojg](https://github.com/ohler55/ojg)
- [BenchmarkBhmjJSONSlice](https://github.com/bhmj/jsonslice)
- [BenchmarkPaesslerAGJSONPath](https://github.com/PaesslerAG/jsonpath)
- [BenchmarkOliveagleJsonpath](https://github.com/oliveagle/jsonpath)

### JSONPath for comparison with more libraries

This is the result of a JSONPath that all libraries were able to process.
Oliveagle/jsonpath is fastest.

```text
JSONPath : $.store.book[0].price
cpu: Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
BenchmarkAsaiYusukeJSONPath_threeLevelsWithIndex-4 5846179 211.3 ns/op 48 B/op 3 allocs/op
BenchmarkOhler55Ojg_threeLevelsWithIndex-4 1721571 689.4 ns/op 1040 B/op 2 allocs/op
BenchmarkBhmjJSONSlice_threeLevelsWithIndex-4 687261 1844 ns/op 24 B/op 1 allocs/op
BenchmarkPaesslerAGJSONPath_threeLevelsWithIndex-4 1892106 639.2 ns/op 208 B/op 7 allocs/op
BenchmarkOliveagleJsonpath_threeLevelsWithIndex-4 13973798 85.53 ns/op 0 B/op 0 allocs/op
```

### A slightly complex JSONPath

Libraries that can handle complex syntax limited to a few.
Among these libraries, my library is fastest.

```text
JSONPath : $..book[?(@.price > $.store.bicycle.price)]
cpu: Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
BenchmarkAsaiYusukeJSONPath_recursiveDescentWithFilter-4 400609 3002 ns/op 464 B/op 20 allocs/op
BenchmarkOhler55Ojg_recursiveDescentWithFilter-4 247669 5094 ns/op 5240 B/op 20 allocs/op
BenchmarkBhmjJSONSlice_recursiveDescentWithFilter-4 59060 20075 ns/op 2936 B/op 57 allocs/op
BenchmarkPaesslerAGJSONPath not supported
BenchmarkOliveagleJsonpath not supported
```

##### JSON used for the benchmark measurement:

<details>
<summary>Show</summary>

```text
{ "store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
```

</details>

##### Benchmark environment:

<details>
<summary>Show</summary>

```text
Processor : Intel Core i5-6267U 2.90GHz
Memory : 16.0 GB
OS : Windows 10
Go version : go1.16 windows/amd64
```

</details>
- [JSONPath Benchmark](https://github.com/AsaiYusuke/jsonpath-benchmark)

## Project progress

Expand Down

0 comments on commit cb2e5eb

Please sign in to comment.