当前位置:网站首页>2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
2022-07-04 21:38:00 【Lin Xidong】
2022 Years. , Made a new one json path
Compatibility and performance test . Comparative testing of three popular frameworks in the market .
disclaimer : Maybe the wrong way to test results in unscientific results ( in addition , Different machines will have different results ), You can point it out in a message . The following test values are only valid for my computer ( To configure :Macbook pro 13 2020 paragraph i7+32G+1T).
The three frameworks and versions used in the test of this case :
- com.alibaba.fastjson2:fastjson2:2.0.4
- com.jayway.jsonpath:json-path:2.2.0
- org.noear:snack3:3.2.31
Three samples of test data :
- A:
{code:1,msg:'Hello world',data:{list:[1,2,3,4,5], ary2:[{a:2},{a:3,b:{c:'ddd'}}]}}
- B:
[{b:{c:1}}, {b:{d:1}}, {b:{c:2}}, {b:{c:23}}]
- C:
[{c:'aaaa'}, {b:'cccc'}, {c:'cccaa'}]
Test plan :
1. Test pseudo code
var text = "...";//1. Pre parse jsonvar obj = JSON.parse(text);long start = System.currentTimeMillis();for(int i=0,len=1000000; i<len; i++) { //2. perform json path JSONPath.eval(obj,"$..."); }//3.100 Ten thousand times of consuming time ( That's the number recorded )long times = System.currentTimeMillis() - start;System.out.println(times);
2. Every frame 、 Each expression executes 4 Time , And record it 3 Time consuming
3. Finally, make a comparison table
4. test result :
Json path expression | data | fastjson2 | json-path | snack3 |
---|---|---|---|---|
$..a | A | 872,764,715 | 2658,2633,2590 | 225,225,232 |
$..* | A | ( Are not compatible 1) | 3227,3220,3156 | 306,315,325 |
$.data.list[1,4] | A | 577,524,419 | 782,798,776 | 133,137,131 |
$.data.list[1:4] | A | 332,367,391 | 941,899,947 | 143,145,146 |
$.data.ary2[1].a | A | 315,339,329 | 704,663,655 | 84,86,80 |
$.data.ary2[*].b.c | A | 642,645,660 | 1105,1025,1050 | 239,235,237 |
$..b[?(@.c == 12)] | B | ( Are not compatible 2) | 5628,5739,5636 | 580,535,532 |
$..c.min() | B | ( Are not compatible 2) | ( Are not compatible 2) | 279,282,285 |
$[?(@.c =~ /a+/)] | C | ( Are not compatible 2) | 3575,3591,3813 | 444,423,429 |
$..ary2[0].a | A | 735,728,736 | 2522,2551,2591 | 310,311,314 |
$.data.list[?(@ in $..ary2[0].a)] | A | ( Are not compatible 2) | 5494,5326,5483 | 678,674,667 |
notes :
- Are not compatible 1 : Returns an empty array directly
- Are not compatible 2 : Direct anomaly
summary
- fastjson2 Poor compatibility
- json-path Poor performance , Functions are limited
- snack3 Best performance , Support two strategies :1. The standard model , Keep up with json-path Compatible effects ;2. Non standard mode , Functions have more room to use
attach 1:snack3 Project address :
attach 2:.. And function expression compatibility
json-path:(snack3 The standard model is the same as ), The strategy is as follows :
- The order in which the selectors are executed :( The expressions in parentheses are processed and then aggregated )
$..(ary2[0].a)
$..(c.min())
// If c Is not an array , There will be an error here$..(ary2[0][0])
- Can only :
data.list[?(@ in $..ary2[0].a)]
- Can only : Execute the function on the original array node
snack3:(snack3 The nonstandard model of ), The strategy is as follows :
The order in which the selectors are executed :( The expressions in parentheses are processed and then aggregated )
($..ary2[0]).a
($..c).min()
//c Is the array normal // In practice , This will be more convenient , Also compatible with other expressions($..ary2[0])[0]
// This will lead to different results // But in practice, there are very few
Sure :
data.list[?(@ in $..ary2[0].a)]
ordata.list[?(@ == $..ary2[0].a[0])]
Sure : Execute the function on the original array node or Execute on query results
attach 3: Test code
com.alibaba.fastjson2:fastjson2
Test code :https://gitee.com/noear/snack3/blob/master/snack3_demo/src/test/java/benchmark/jsonpath/SpeedFastjson2JsonPathTest.javacom.jayway.jsonpath:json-path
Test code :https://gitee.com/noear/snack3/blob/master/snack3_demo/src/test/java/benchmark/jsonpath/SpeedJaywayJsonPathTest.javaorg.noear:snack3
Test code :https://gitee.com/noear/snack3/blob/master/snack3_demo/src/test/java/benchmark/jsonpath/SpeedJsonPathTest.java
边栏推荐
- [C language] deep understanding of symbols
- redis管道
- 华为模拟器ensp常用命令
- Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
- Flutter TextField示例
- Golang面试整理 三 简历如何书写
- TCP shakes hands three times and waves four times. Do you really understand?
- Embedded TC test case
- 【活动早知道】LiveVideoStack近期活动一览
- 杰理之AD 系列 MIDI 功能说明【篇】
猜你喜欢
Jerry's ad series MIDI function description [chapter]
LambdaQueryWrapper用法
Compréhension approfondie du symbole [langue C]
Routing configuration and connectivity test of Huawei simulator ENSP
Huawei ENSP simulator configures DHCP for router
maya灯建模
OMS系统实战的三两事
巅峰不止,继续奋斗!城链科技数字峰会于重庆隆重举行
Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
迈动互联中标北京人寿保险
随机推荐
B站视频 声音很小——解决办法
[ 每周译Go ] 《How to Code in Go》系列文章上线了!!
杰理之AD 系列 MIDI 功能说明【篇】
Procurement in software development
学习突围3 - 关于精力
Flutter 返回按钮的监听
LambdaQueryWrapper用法
杰理之AD 系列 MIDI 功能说明【篇】
Jerry's ad series MIDI function description [chapter]
For MySQL= No data equal to null can be found. Solution
Go语言循环语句(第10课中3)
torch. Tensor and torch The difference between tensor
类方法和类变量的使用
杰理之增加进关机前把触摸模块关闭流程【篇】
Monitor the shuttle return button
【C語言】符號的深度理解
MYSQL 用!=查询不出等于null的数据,解决办法
华为ensp模拟器实现通信安全(交换机)
Drop down selection of Ehlib database records
Redis pipeline