当前位置:网站首页>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
边栏推荐
- Flutter 返回按钮的监听
- 输入的查询SQL语句,是如何执行的?
- IIC (STM32)
- Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
- Delphi SOAP WebService 服务器端多个 SoapDataModule 实现相同的接口方法,接口继承
- Jerry's ad series MIDI function description [chapter]
- [early knowledge of activities] list of recent activities of livevideostack
- Jerry's ad series MIDI function description [chapter]
- Delphi soap WebService server-side multiple soapdatamodules implement the same interface method, interface inheritance
- redis发布订阅的使用
猜你喜欢

Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)

巅峰不止,继续奋斗!城链科技数字峰会于重庆隆重举行

华为ensp模拟器 实现多个路由器的设备可以相互访问

B站视频 声音很小——解决办法
![Jerry added the process of turning off the touch module before turning it off [chapter]](/img/28/5e4eb39243a0c973d0b90f76571f9b.png)
Jerry added the process of turning off the touch module before turning it off [chapter]

How to use concurrentlinkedqueue as a cache queue

y56.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(二九)

TCP shakes hands three times and waves four times. Do you really understand?

如何使用ConcurrentLinkedQueue做一个缓存队列

ArcGIS 10.2.2 | solution to the failure of ArcGIS license server to start
随机推荐
Day24: file system
Test case (TC)
Redis bloom filter
Billions of citizens' information has been leaked! Is there any "rescue" for data security on the public cloud?
Jerry's ad series MIDI function description [chapter]
2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
【活动早知道】LiveVideoStack近期活动一览
应用实践 | 蜀海供应链基于 Apache Doris 的数据中台建设
Procurement in software development
Shutter WebView example
__init__() missing 2 required positional arguments 不易查明的继承错误
Maidong Internet won the bid of Beijing life insurance
旋变串判断
如何借助自动化工具落地DevOps
SolidWorks工程图添加材料明细表的操作
Can be displayed in CAD but not displayed in print
IIC (STM32)
redis03——Redis的网络配置与心跳机制
In the release version, the random white screen does not display the content after opening the shutter
For MySQL= No data equal to null can be found. Solution