当前位置:网站首页>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
边栏推荐
- Interpreting the development of various intelligent organizations in maker Education
- UTF encoding and character set in golang
- Minidom module writes and parses XML
- Jerry's ad series MIDI function description [chapter]
- TCP三次握手,四次挥手,你真的了解吗?
- Flutter在 release版本,打开后随机白屏不显示内容
- redis03——Redis的网络配置与心跳机制
- For MySQL= No data equal to null can be found. Solution
- Huawei ENSP simulator layer 3 switch
- torch. Tensor and torch The difference between tensor
猜你喜欢
MP3是如何诞生的?
[ 每周译Go ] 《How to Code in Go》系列文章上线了!!
Enlightenment of maker thinking in Higher Education
华为ensp模拟器 配置ACL访问控制列表
案例分享|金融业数据运营运维一体化建设
torch.tensor和torch.Tensor的区别
如何使用ConcurrentLinkedQueue做一个缓存队列
How to remove the black dot in front of the title in word document
[C language] deep understanding of symbols
ArcGIS 10.2.2 | solution to the failure of ArcGIS license server to start
随机推荐
学习突围3 - 关于精力
Jerry's ad series MIDI function description [chapter]
面试官:说说XSS攻击是什么?
[leetcode] 17. Letter combination of telephone number
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
Daily question -leetcode1200- minimum absolute difference - array - sort
Redis bloom filter
[early knowledge of activities] list of recent activities of livevideostack
华为ensp模拟器 实现多个路由器的设备可以相互访问
Billions of citizens' information has been leaked! Is there any "rescue" for data security on the public cloud?
[weekly translation go] how to code in go series articles are online!!
torch. Tensor and torch The difference between tensor
B站视频 声音很小——解决办法
2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
杰理之AD 系列 MIDI 功能说明【篇】
LambdaQueryWrapper用法
__ init__ () missing 2 required positive arguments
Flutter 返回按钮的监听
WGCNA分析基本教程总结
Huawei simulator ENSP common commands