-
Notifications
You must be signed in to change notification settings - Fork 501
fastjson_benchmark
更多测试数据看这里 https://github.com/alibaba/fastjson2/tree/main/docs/benchmark
- fastjson2 2.0.38
- fastjson1 1.1.83
- jackson 2.15.1
- gson 2.10.1
- kryo 5.5.0
- hessian 4.0.66
都是截止测试时间(2023-06-18)各个库的最新版本
测试的服务器基于阿里云最新代ECS,包括x64架构的Intel和阿里云平头哥的倚天处理器。
ecs.c8i.xlarge
ecs.c8y.xlarge
Orange Pi 5 Plus
推荐阿里云平头哥Yitian 170 CPU的机器,性能快20%,价格便宜40%
这个是阿里云当前代标准型ECS,处理器型号 Intel Xeon(Sapphire Rapids) Platinum 8475B,4核,8G内存
按量付费每小时0.8562元
这个是阿里云上售卖ARM处理器,处理器型号 Yitian 710,4核,8G内存。这个是阿里云平头哥的倚天710处理器。
按量付费每个小时0.533866元
这个是国产的树莓派的高性能替代 http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-plus.html 8核16G内存 天猫价949元
基于Oracle最新版本的Linux x64/aarch64的JDK版本,下载地址 https://www.oracle.com/java/technologies/
- oracle-jdk1.8.0_371
- oracle-jdk-11.0.19
- oracle-jdk-17.0.7
- graalvm-17.0.7
-
运行方式测试代码方式 需要准备响应的JDK版本到Install目录下
git clone https://github.com/alibaba/fastjson2
cd fastjson2
git checkout 2.0.38
mvn clean install -Dmaven.test.skip
~/Install/jdk8/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay
~/Install/jdk11/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay
~/Install/jdk17/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay
~/Install/graalvm-17/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay
原始数据 https://github.com/alibaba/fastjson2/blob/2.0.38/docs/benchmark/benchmark_2.0.38_raw.md
这个是最常用的场景,将JSON格式字符串反序列化为Java对象,这个场景在fastjson中的代码如下:
String str = "...";
Bean bean = JSON.parseJSONObject(str, Bean.class);
这个场景是fastjson1最强的场景;
在ecs.c8i.large-jdk11.0.19环境中,fastjson1只相当于只相当于fastjson2的54.2% ;jackson则只相当于fastjson2的26.74%; gson是fastjson2的27.09%,也就是说这个最常见的反序列化场景,fastjson2的性能差不多是jackson/gson的3~4倍。
性能排序如下:
// aliyun.c8i.large jdk-11.0.19
fastjson2 > fastjson1 > jackson > gson
jdk8 100% 69.63% 34.43% 31.42%
jdk11 100% 54.20% 26.74% 27.09%
jdk17 100% 66.08% 25.64% 25.66%
下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。
aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
---|---|---|---|---|---|
aliyun_ecs.c8i.large | jdk1.8.0_371 | 3221.266 | 2242.933 (69.63%) | 1109.039 (34.43%) | 1012.118 (31.42%) |
jdk-11.0.19 | 3613.833 | 1958.644 (54.2%) | 966.209 (26.74%) | 979.065 (27.09%) | |
jdk-17.0.7 | 3973.012 | 2625.245 (66.08%) | 1018.698 (25.64%) | 1019.617 (25.66%) | |
graalvm_17.0.7+8.1 | 3800.747 | 3504.45 (92.2%) | 1074.656 (28.27%) | 1056.828 (27.81%) | |
aliyun_ecs.c8y.large | jdk1.8.0_371 | 4494.846 | 3085.452 (68.64%) | 1358.267 (30.22%) | 1412.577 (31.43%) |
jdk-11.0.19 | 5119.561 | 2915.271 (56.94%) | 1330.856 (26%) | 1411.811 (27.58%) | |
jdk-17.0.7 | 5115.273 | 4034.262 (78.87%) | 1361.581 (26.62%) | 1455.136 (28.45%) | |
graalvm_17.0.7+8.1 | 6028.42 | 4566.464 (75.75%) | 1424.79 (23.63%) | 1551.452 (25.74%) | |
orangepi5p | jdk1.8.0_371 | 3445.427 | 2378.522 (69.03%) | 1055.049 (30.62%) | 936.473 (27.18%) |
jdk-11.0.19 | 3673.967 | 2216.18 (60.32%) | 985.666 (26.83%) | 949.401 (25.84%) | |
jdk-17.0.7 | 3713.943 | 3194.434 (86.01%) | 1052.409 (28.34%) | 962.907 (25.93%) | |
graalvm_17.0.7+8.1 | 4005.105 | 3388.239 (84.6%) | 1020.092 (25.47%) | 1002.879 (25.04%) |
这个场景是将格式化过的JSON格式字符串反序列化为Java对象,这个场景fastjson1的parse算法不擅长的。这个场景fastjson2表现仍然非常好,性能是jackson/gson两倍以上。 这个场景在ecs.c7.xlarge-jdk11.0.19环境下,fastjson1的性能是fastjson2的24.02%,jackson的性能是fastjson2的37.89%,gson是fastjson2的38.40%.
这个场景在fastjson中的代码如下:
// 这里输入的是格式化过后的json字符串
String str = "{\n" +
"\t\"id\":123\n" +
"}";
Bean bean = JSON.parseJSONObject(str, Bean.class);
性能排序分别如下:
// aliyun.c8i.large jdk-11.0.19
fastjson2 > jackson > gson > fastjson1
jdk8 100% 44.54% 43.08% 27.02%
jdk11 100% 37.89% 38.40% 24.02%
jdk17 100% 36.14% 36.96% 24.88%
下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。
aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
---|---|---|---|---|---|
aliyun_ecs.c8i.large | jdk1.8.0_371 | 2195.574 | 593.286 (27.02%) | 977.868 (44.54%) | 945.917 (43.08%) |
jdk-11.0.19 | 2406.061 | 577.909 (24.02%) | 911.648 (37.89%) | 923.991 (38.4%) | |
jdk-17.0.7 | 2500.245 | 622.087 (24.88%) | 903.489 (36.14%) | 924.062 (36.96%) | |
graalvm_17.0.7+8.1 | 2624.355 | 887.51 (33.82%) | 979.826 (37.34%) | 1021.753 (38.93%) | |
aliyun_ecs.c8y.large | jdk1.8.0_371 | 2573.696 | 863.006 (33.53%) | 1250.197 (48.58%) | 1285.911 (49.96%) |
jdk-11.0.19 | 3699.667 | 900.438 (24.34%) | 1235.737 (33.4%) | 1308.175 (35.36%) | |
jdk-17.0.7 | 3626.674 | 978.883 (26.99%) | 1268.003 (34.96%) | 1321.231 (36.43%) | |
graalvm_17.0.7+8.1 | 4027.298 | 1260.976 (31.31%) | 1317.09 (32.7%) | 1386.659 (34.43%) | |
orangepi5p | jdk1.8.0_371 | 2260.166 | 641.796 (28.4%) | 992.252 (43.9%) | 853.837 (37.78%) |
jdk-11.0.19 | 2709.243 | 631.214 (23.3%) | 939.866 (34.69%) | 882.503 (32.57%) | |
jdk-17.0.7 | 2774.937 | 717.55 (25.86%) | 966.043 (34.81%) | 880.826 (31.74%) | |
graalvm_17.0.7+8.1 | 2978.413 | 873.507 (29.33%) | 947.676 (31.82%) | 914.082 (30.69%) |
这个场景是将JSON格式字符串反序列化为JSONObject,这也是一个最常见的场景之一,这个场景在fastjson中的代码如下:
String str = "...";
JSONObject jsonObject = JSON.parseJSONObject(str);
fastjson2在这个场景也表现了远超fastjson1/jackson/gson的性能。 在不同的环境中,fastjson1和jackson都只能相当于fastjson2性能的40%~60%,gson则更差一些。
性能排序如下:
// aliyun.c8i.large jdk-11.0.19
fastjson2 > fastjson1 > jackson > gson
jdk8 100% 50.32% 52.09% 36.63%
jdk11 100% 44.70% 43.27% 34.15%
jdk17 100% 62.32% 48.29% 34.02%
下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。
aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
---|---|---|---|---|---|
aliyun_ecs.c8i.large | jdk1.8.0_371 | 2308.295 | 1161.647 (50.32%) | 1221.142 (52.9%) | 845.488 (36.63%) |
jdk-11.0.19 | 2312.525 | 1033.696 (44.7%) | 1000.604 (43.27%) | 789.739 (34.15%) | |
jdk-17.0.7 | 2421.896 | 1267.024 (52.32%) | 1169.475 (48.29%) | 823.942 (34.02%) | |
graalvm_17.0.7+8.1 | 2546.739 | 1564.245 (61.42%) | 1203.007 (47.24%) | 1046.601 (41.1%) | |
aliyun_ecs.c8y.large | jdk1.8.0_371 | 2453.582 | 1249.739 (50.94%) | 1157.061 (47.16%) | 1079.984 (44.02%) |
jdk-11.0.19 | 2712.86 | 1353.584 (49.9%) | 1197.57 (44.14%) | 1131.413 (41.71%) | |
jdk-17.0.7 | 2790.418 | 1464.686 (52.49%) | 1363.403 (48.86%) | 1109.238 (39.75%) | |
graalvm_17.0.7+8.1 | 3193.555 | 2149.562 (67.31%) | 1609.49 (50.4%) | 1348.553 (42.23%) | |
orangepi5p | jdk1.8.0_371 | 1828.422 | 996.394 (54.49%) | 968.087 (52.95%) | 800.608 (43.79%) |
jdk-11.0.19 | 1898.106 | 938.91 (49.47%) | 952.651 (50.19%) | 793.473 (41.8%) | |
jdk-17.0.7 | 1950.183 | 1142.31 (58.57%) | 1055.501 (54.12%) | 774.314 (39.7%) | |
graalvm_17.0.7+8.1 | 2048.535 | 1468.443 (71.68%) | 1113.235 (54.34%) | 900.361 (43.95%) |
这个是将UTF8格式的byte数组反序列化为Java对象,这个场景在缓存和RPC场景中常用。
这个场景在fastjson中的代码如下:
byte[] utf8Bytes = ...;
Bean bean = JSON.parseJSONObject(utf8Bytes, Bean.class);
这个场景fastjson2同样表现出了卓越的性能;在JDK11下,fastjson1和jackson的性能分别之后fastjson2的83.65%和54.88%; gson不直接支持输入utf8Bytes,需要先构造字符串,性能只有fastjson2的48.55%。
性能排序如下:
// aliyun.c8i.large jdk-11.0.19
fastjson2 > fastjson1 > jackson > gson
jdk8 100% 92.71% 59.03% 46.60%
jdk11 100% 83.65% 54.88% 48.55%
jdk17 100% 51.33% 27.44% 25.67%
下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。
aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
---|---|---|---|---|---|
aliyun_ecs.c8i.large | jdk1.8.0_371 | 1977.18 | 1832.974 (92.71%) | 1167.157 (59.03%) | 921.451 (46.6%) |
jdk-11.0.19 | 2015.94 | 1686.276 (83.65%) | 1106.353 (54.88%) | 978.692 (48.55%) | |
jdk-17.0.7 | 3988.767 | 2047.328 (51.33%) | 1094.653 (27.44%) | 1024.003 (25.67%) | |
graalvm_17.0.7+8.1 | 4250.886 | 2389.483 (56.21%) | 1219.817 (28.7%) | 1036.333 (24.38%) | |
aliyun_ecs.c8y.large | jdk1.8.0_371 | 2062.255 | 2631.821 (127.62%) | 1538.505 (74.6%) | 1294.582 (62.78%) |
jdk-11.0.19 | 2024.101 | 2426.41 (119.88%) | 1462.141 (72.24%) | 1344.386 (66.42%) | |
jdk-17.0.7 | 5065.362 | 3035.012 (59.92%) | 1379.408 (27.23%) | 1344.481 (26.54%) | |
graalvm_17.0.7+8.1 | 6002.851 | 3037.623 (50.6%) | 1404.874 (23.4%) | 1510.224 (25.16%) | |
orangepi5p | jdk1.8.0_371 | 3087.647 | 1818.093 (58.88%) | 1238.117 (40.1%) | 834.7 (27.03%) |
jdk-11.0.19 | 1473.766 | 1785.737 (121.17%) | 1153.148 (78.24%) | 895.65 (60.77%) | |
jdk-17.0.7 | 3642.698 | 2236.471 (61.4%) | 1168.103 (32.07%) | 915.462 (25.13%) | |
graalvm_17.0.7+8.1 | 4493.511 | 2030.083 (45.18%) | 1057.978 (23.54%) | 952.319 (21.19%) |
这个是Java对象序列化成字符串, 这个是序列化最常用的场景之一。这个场景在fastjson中的代码如下:
Bean bean = ...;
String str = JSON.toJSONString(bean);
在这个最常用的序列化场景,fastjson2表现出远超fastjson1/jackson/gson的性能;这个场景gson表现很差,只有fastjson2的20~30%。
性能排序如下:
// aliyun.c8i.large jdk-11.0.19
fastjson2 > jackson > fastjson1 > gson
jdk8 100% 60.71% 44.73% 29.33%
jdk11 100% 63.11% 44.97% 26.24%
jdk17 100% 57.47% 41.34% 19.24%
下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。
aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
---|---|---|---|---|---|
aliyun_ecs.c8i.large | jdk1.8.0_371 | 3453.441 | 1544.712 (44.73%) | 2096.436 (60.71%) | 1013.014 (29.33%) |
jdk-11.0.19 | 3144.537 | 1414.201 (44.97%) | 1984.459 (63.11%) | 825.115 (26.24%) | |
jdk-17.0.7 | 3652.012 | 1509.688 (41.34%) | 2098.898 (57.47%) | 702.7 (19.24%) | |
graalvm_17.0.7+8.1 | 4994.468 | 1802.098 (36.08%) | 2565.164 (51.36%) | 720.686 (14.43%) | |
aliyun_ecs.c8y.large | jdk1.8.0_371 | 4694.206 | 2036.215 (43.38%) | 2419.939 (51.55%) | 1335.542 (28.45%) |
jdk-11.0.19 | 5214.882 | 1874.401 (35.94%) | 2626.637 (50.37%) | 1296.637 (24.86%) | |
jdk-17.0.7 | 5168.969 | 2868.758 (55.5%) | 2617.835 (50.65%) | 863.974 (16.71%) | |
graalvm_17.0.7+8.1 | 6234.468 | 2834.519 (45.47%) | 3139.284 (50.35%) | 869.592 (13.95%) | |
orangepi5p | jdk1.8.0_371 | 3444.148 | 1327.27 (38.54%) | 1829.602 (53.12%) | 828.635 (24.06%) |
jdk-11.0.19 | 3948.42 | 1293.318 (32.76%) | 1832.6 (46.41%) | 771.026 (19.53%) | |
jdk-17.0.7 | 3962.325 | 1357.162 (34.25%) | 1913.307 (48.29%) | 742.996 (18.75%) | |
graalvm_17.0.7+8.1 | 4360.2 | 1714.457 (39.32%) | 2053.774 (47.1%) | 702.916 (16.12%) |
这个是Java对象序列化成UTF格式的byte数组, 这个是最常用的场景之一,在缓存和RPC场景常用。gson不直接支持,需要先序列化为String再转换为UTF8格式的byte数组。
这个场景在fastjson中的代码如下:
Bean bean = ...;
byte[] utf8Bytes = JSON.toJSONBytes(bean);
在这个最常用的序列化场景,fastjson2表现出远超fastjson1/jackson/gson的性能;这个场景gson表现很差。
性能排序如下:
// aliyun.c8i.large jdk-11.0.19
fastjson2 > jackson > fastjson1 > gson
jdk8 100% 48.41% 35.80% 20.93%
jdk11 100% 42.08% 30.26% 17.20%
jdk17 100% 41.86% 28.69% 14.74%
下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。
aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
---|---|---|---|---|---|
aliyun_ecs.c8i.large | jdk1.8.0_371 | 3919.186 | 1403.078 (35.8%) | 1897.285 (48.41%) | 820.19 (20.93%) |
jdk-11.0.19 | 4357.953 | 1318.596 (30.26%) | 1833.879 (42.08%) | 749.533 (17.2%) | |
jdk-17.0.7 | 4806.761 | 1379.009 (28.69%) | 2011.915 (41.86%) | 708.316 (14.74%) | |
graalvm_17.0.7+8.1 | 7092.941 | 1570.59 (22.14%) | 2527.526 (35.63%) | 693.861 (9.78%) | |
aliyun_ecs.c8y.large | jdk1.8.0_371 | 5656.607 | 1816.323 (32.11%) | 2509.041 (44.36%) | 1203.651 (21.28%) |
jdk-11.0.19 | 6200.766 | 2460.952 (39.69%) | 2467.552 (39.79%) | 1174.549 (18.94%) | |
jdk-17.0.7 | 6214.725 | 1906.136 (30.67%) | 2652.071 (42.67%) | 840.24 (13.52%) | |
graalvm_17.0.7+8.1 | 8912.5 | 2219.152 (24.9%) | 3307.732 (37.11%) | 847.831 (9.51%) | |
orangepi5p | jdk1.8.0_371 | 4473.541 | 1268.835 (28.36%) | 1856.253 (41.49%) | 766.237 (17.13%) |
jdk-11.0.19 | 4757.054 | 1671.044 (35.13%) | 1665.372 (35.01%) | 775.736 (16.31%) | |
jdk-17.0.7 | 4765.497 | 1322.229 (27.75%) | 1847.5 (38.77%) | 689.419 (14.47%) | |
graalvm_17.0.7+8.1 | 5797.292 | 1370.942 (23.65%) | 2153.015 (37.14%) | 704.307 (12.15%) |
这个场景是JSONObject序列化成字符串, 这个是序列化最常用的场景之一。这个场景在fastjson中的代码如下:
JSONObject jsonObject = ...;
String str = jsonObject.toJSONString();
在这个最常用的序列化场景,fastjson2表现出远超fastjson1/jackson/gson的性能;这个场景gson表现很差,只有fastjson2的1/3
性能排序如下:
// aliyun.c8i.large jdk-11.0.19
fastjson2 > jackson > fastjson1 > gson
jdk8 100% 60.67% 60.22% 33.94%
jdk11 100% 75.28% 72.96% 33.88%
jdk17 100% 54.67% 50.49% 22.56%
aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
---|---|---|---|---|---|
aliyun_ecs.c8i.large | jdk1.8.0_371 | 3290.427 | 1981.376 (60.22%) | 1996.458 (60.67%) | 1116.662 (33.94%) |
jdk-11.0.19 | 2482.387 | 1811.135 (72.96%) | 1868.703 (75.28%) | 841.097 (33.88%) | |
jdk-17.0.7 | 3302.446 | 1667.502 (50.49%) | 1805.558 (54.67%) | 744.965 (22.56%) | |
graalvm_17.0.7+8.1 | 3153.111 | 2180.628 (69.16%) | 2241.947 (71.1%) | 732.213 (23.22%) | |
aliyun_ecs.c8y.large | jdk1.8.0_371 | 3624.017 | 2242.952 (61.89%) | 2280.145 (62.92%) | 1556.246 (42.94%) |
jdk-11.0.19 | 3671.136 | 2453.945 (66.84%) | 2519.955 (68.64%) | 1407.823 (38.35%) | |
jdk-17.0.7 | 4268.287 | 2444.751 (57.28%) | 2417.296 (56.63%) | 872.511 (20.44%) | |
graalvm_17.0.7+8.1 | 4808.186 | 3234.224 (67.26%) | 3103.167 (64.54%) | 901.186 (18.74%) | |
orangepi5p | jdk1.8.0_371 | 2519.485 | 1541.899 (61.2%) | 1717.911 (68.19%) | 1020.167 (40.49%) |
jdk-11.0.19 | 2391.985 | 1586.443 (66.32%) | 1825.003 (76.3%) | 906.815 (37.91%) | |
jdk-17.0.7 | 2795.34 | 1607.015 (57.49%) | 1823.316 (65.23%) | 765.379 (27.38%) | |
graalvm_17.0.7+8.1 | 2857.305 | 1949.845 (68.24%) | 2066.624 (72.33%) | 757.41 (26.51%) |
这个场景是将JavaBean序列化成二进制格式并且带类型信息, 这个是代替Java/Hessian序列化的场景,代码如下:
JSONB.toBytes(
mc,
JSONWriter.Feature.WriteClassName,
JSONWriter.Feature.IgnoreNoneSerializable,
JSONWriter.Feature.FieldBased,
JSONWriter.Feature.ReferenceDetection,
JSONWriter.Feature.WriteNulls,
JSONWriter.Feature.NotWriteDefaultValue,
JSONWriter.Feature.NotWriteHashMapArrayListClassName,
JSONWriter.Feature.WriteNameAsSymbol
)
这个场景下,fastjson_jsonb的性能是hessian的4~5倍
性能排序如下:
// aliyun.c8i.large
fastjson2_jsonb > hessian > javaSerialize
jdk8 100% 26.90% 16.60%
jdk11 100% 28.26% 17.05%
jdk17 100% 22.98% 15.20%
下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是hessian/fastjson2_jsonb的百分数表示。
aliyun ecs spec | jdk version | fastjson2JSONB | hessian | javaSerialize |
---|---|---|---|---|
aliyun_ecs.c8i.large | jdk1.8.0_371 | 3197.58 | 860.245 (26.9%) | 530.687 (16.6%) |
jdk-11.0.19 | 2942.848 | 831.574 (28.26%) | 501.648 (17.05%) | |
jdk-17.0.7 | 3433.635 | 789.111 (22.98%) | 521.834 (15.2%) | |
graalvm_17.0.7+8.1 | 4050.809 | 1184.406 (29.24%) | 572.202 (14.13%) | |
aliyun_ecs.c8y.large | jdk1.8.0_371 | 4549.146 | 1132.452 (24.89%) | 803.564 (17.66%) |
jdk-11.0.19 | 4314.591 | 1030.165 (23.88%) | 883.803 (20.48%) | |
jdk-17.0.7 | 4456.677 | 1159.317 (26.01%) | 824.018 (18.49%) | |
graalvm_17.0.7+8.1 | 6469.423 | 1272.237 (19.67%) | 812.61 (12.56%) | |
orangepi5p | jdk1.8.0_371 | 3236.393 | 656.509 (20.29%) | 560.317 (17.31%) |
jdk-11.0.19 | 3071.905 | 650.44 (21.17%) | 554.274 (18.04%) | |
jdk-17.0.7 | 3123.57 | 668.721 (21.41%) | 574.46 (18.39%) | |
graalvm_17.0.7+8.1 | 3777.299 | 685.876 (18.16%) | 533.273 (14.12%) |
这个场景是JavaBean二进制带类型信息反序列化的场景, 这个是代替Java/Hessian反序列化的场景,代码如下:
JSONB.parseObject(
fastjson2JSONBBytes,
Object.class,
JSONReader.Feature.SupportAutoType,
JSONReader.Feature.IgnoreNoneSerializable,
JSONReader.Feature.UseDefaultConstructorAsPossible,
JSONReader.Feature.UseNativeObject,
JSONReader.Feature.FieldBased)
这个场景下,fastjson2二进制格式性能是hessian的58倍,是Java序列化的3040倍
性能排序如下:
// aliyun.c8i.large jdk-11.0.19
fastjson2_jsonb > hessian > javaSerialize
jdk8 100% 16.85% 2.92%
jdk11 100% 13.94% 2.57%
jdk17 100% 13.46% 2.62%
下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是hessian/fastjson2_jsonb的百分数表示。
aliyun ecs spec | jdk version | fastjson2JSONB | hessian | javaSerialize |
---|---|---|---|---|
aliyun_ecs.c8i.large | jdk1.8.0_371 | 3971.943 | 669.159 (16.85%) | 115.828 (2.92%) |
jdk-11.0.19 | 4461.243 | 621.804 (13.94%) | 114.514 (2.57%) | |
jdk-17.0.7 | 4950.269 | 666.261 (13.46%) | 129.525 (2.62%) | |
graalvm_17.0.7+8.1 | 5333.887 | 770.852 (14.45%) | 142.247 (2.67%) | |
aliyun_ecs.c8y.large | jdk1.8.0_371 | 5442.412 | 312.793 (5.75%) | 154.667 (2.84%) |
jdk-11.0.19 | 5748.207 | 371.625 (6.47%) | 157.537 (2.74%) | |
jdk-17.0.7 | 6069.257 | 380.466 (6.27%) | 155.871 (2.57%) | |
graalvm_17.0.7+8.1 | 6330.204 | 495.17 (7.82%) | 169.669 (2.68%) | |
orangepi5p | jdk1.8.0_371 | 3424.885 | 179.523 (5.24%) | 122.566 (3.58%) |
jdk-11.0.19 | 3713.104 | 184.939 (4.98%) | 113.481 (3.06%) | |
jdk-17.0.7 | 3848.843 | 195.649 (5.08%) | 128.512 (3.34%) | |
graalvm_17.0.7+8.1 | 4680.693 | 241.944 (5.17%) | 130.163 (2.78%) |