当前位置:网站首页>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:fastjson2Test code :https://gitee.com/noear/snack3/blob/master/snack3_demo/src/test/java/benchmark/jsonpath/SpeedFastjson2JsonPathTest.javacom.jayway.jsonpath:json-pathTest code :https://gitee.com/noear/snack3/blob/master/snack3_demo/src/test/java/benchmark/jsonpath/SpeedJaywayJsonPathTest.javaorg.noear:snack3Test code :https://gitee.com/noear/snack3/blob/master/snack3_demo/src/test/java/benchmark/jsonpath/SpeedJsonPathTest.java
边栏推荐
猜你喜欢

Huawei ENSP simulator configures DHCP for router

Maidong Internet won the bid of Beijing life insurance

应用实践 | 蜀海供应链基于 Apache Doris 的数据中台建设
![Jerry's ad series MIDI function description [chapter]](/img/d7/348d85eb9f69ffd75612eeba56b16e.png)
Jerry's ad series MIDI function description [chapter]

杰理之AD 系列 MIDI 功能说明【篇】

Billions of citizens' information has been leaked! Is there any "rescue" for data security on the public cloud?

杰理之增加进关机前把触摸模块关闭流程【篇】

解析互联网时代的创客教育技术

每日一题-LeetCode556-下一个更大元素III-字符串-双指针-next_permutation

Can be displayed in CAD but not displayed in print
随机推荐
Analysis of maker education technology in the Internet Era
IIC (STM32)
华为ensp模拟器 实现多个路由器的设备可以相互访问
超详细教程,一文入门Istio架构原理及实战应用
MYSQL 用!=查询不出等于null的数据,解决办法
改善机器视觉系统的方法
Lambdaquerywrapper usage
TCP三次握手,四次挥手,你真的了解吗?
WGCNA分析基本教程总结
Learning breakout 3 - about energy
杰理之AD 系列 MIDI 功能说明【篇】
输入的查询SQL语句,是如何执行的?
2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
杰理之AD 系列 MIDI 功能说明【篇】
Shutter textfield example
redis缓存
TCP shakes hands three times and waves four times. Do you really understand?
[buuctf.reverse] 151_ [FlareOn6]DnsChess
Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)
SolidWorks工程图添加材料明细表的操作