-
Notifications
You must be signed in to change notification settings - Fork 495
fastjson_benchmark
更多测试数据看这里 https://github.com/alibaba/fastjson2/tree/main/docs/benchmark
- fastjson2 2.0.34
- 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
这个是阿里云当前代标准型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.34
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.34/docs/benchmark/benchmark_2.0.34_raw.md
这个是最常用的场景,将JSON格式字符串反序列化为Java对象,这个场景在fastjson中的代码如下:
String str = "...";
Bean bean = JSON.parseJSONObject(str, Bean.class);
这个场景是fastjson1最强的场景;
在ecs.c8i.large-jdk11.0.19环境中,fastjson1只相当于只相当于fastjson2的71.55% ;jackson则只相当于fastjson2的35.21%; gson是fastjson2的35.36%,也就是说这个最常见的反序列化场景,fastjson2的性能差不多是jackson/gson的三倍。
性能排序如下:
// aliyun_ecs.g8i.large
fastjson2 > fastjson1 > jackson > gson
jdk8 100% 85% 41.67% 37.08%
jdk11 100% 71.55% 35.21% 35.68%
jdk17 100% 91.91% 35.91% 36.29%
下面是不同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.g8i.large | jdk1.8.0_371 | 2582.255 | 2194.912 (85%) | 1076.041 (41.67%) | 957.543 (37.08%) |
jdk-11.0.19 | 2753.434 | 1970.107 (71.55%) | 969.615 (35.21%) | 982.558 (35.68%) | |
jdk-17.0.7 | 2879.11 | 2646.103 (91.91%) | 1033.83 (35.91%) | 1044.744 (36.29%) | |
graalvm_17.0.7+8.1 | 2877.882 | 3490.823 (121.3%) | 1074.694 (37.34%) | 1045.023 (36.31%) | |
aliyun_ecs.g8y.large | jdk1.8.0_371 | 4013.19 | 3080.664 (76.76%) | 1387.022 (34.56%) | 1414.971 (35.26%) |
jdk-11.0.19 | 4150.442 | 3027.893 (72.95%) | 1352.156 (32.58%) | 1423.13 (34.29%) | |
jdk-17.0.7 | 4247.923 | 4114.055 (96.85%) | 1420.088 (33.43%) | 1425.616 (33.56%) | |
graalvm_17.0.7+8.1 | 4564.054 | 4711.368 (103.23%) | 1456.355 (31.91%) | 1570.283 (34.41%) | |
orangepi5p | jdk1.8.0_371 | 3163.978 | 2663.744 (84.19%) | 1190.413 (37.62%) | 1067.005 (33.72%) |
jdk-11.0.19 | 3245.9 | 2561.117 (78.9%) | 1105.771 (34.07%) | 1072.671 (33.05%) | |
jdk-17.0.7 | 3270.943 | 3567.236 (109.06%) | 1204.83 (36.83%) | 1087.251 (33.24%) | |
graalvm_17.0.7+8.1 | 3596.944 | 4217.008 (117.24%) | 1162.206 (32.31%) | 1148.028 (31.92%) |
这个场景是将格式化过的JSON格式字符串反序列化为Java对象,这个场景fastjson1的parse算法不擅长的。这个场景fastjson2表现仍然非常好,性能是jackson/gson两倍以上。 这个场景在ecs.c7.xlarge-jdk1.8.0_361环境下,fastjson1的性能是fastjson2的27.83%,jackson的性能是fastjson2的50.51%,gson是fastjson2的42.48%%.
这个场景在fastjson中的代码如下:
// 这里输入的是格式化过后的json字符串
String str = "{\n" +
"\t\"id\":123\n" +
"}";
Bean bean = JSON.parseJSONObject(str, Bean.class);
性能排序分别如下:
// aliyun_ecs.g8i.large
fastjson2 > jackson > gson > fastjson1
jdk8 100% 50.31% 47.97% 30.03%
jdk11 100% 45.21% 42.53% 29.13%
jdk17 100% 46.78% 45.19% 31.89%
下面是不同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.g8i.large | jdk1.8.0_371 | 1951.123 | 586.008 (30.03%) | 981.529 (50.31%) | 935.943 (47.97%) |
jdk-11.0.19 | 1980.14 | 576.837 (29.13%) | 895.231 (45.21%) | 842.114 (42.53%) | |
jdk-17.0.7 | 1936.139 | 617.388 (31.89%) | 905.749 (46.78%) | 874.874 (45.19%) | |
graalvm_17.0.7+8.1 | 2074.951 | 860.298 (41.46%) | 962.607 (46.39%) | 983.036 (47.38%) | |
aliyun_ecs.g8y.large | jdk1.8.0_371 | 1816.268 | 863.233 (47.53%) | 1266.37 (69.72%) | 1303.309 (71.76%) |
jdk-11.0.19 | 3198.409 | 904.486 (28.28%) | 1249.957 (39.08%) | 1338.467 (41.85%) | |
jdk-17.0.7 | 2997.572 | 959.907 (32.02%) | 1299.603 (43.36%) | 1322.768 (44.13%) | |
graalvm_17.0.7+8.1 | 3277.775 | 1298.414 (39.61%) | 1325.719 (40.45%) | 1430.954 (43.66%) | |
orangepi5p | jdk1.8.0_371 | 2579.831 | 713.589 (27.66%) | 1111.452 (43.08%) | 964.844 (37.4%) |
jdk-11.0.19 | 2593.822 | 718.589 (27.7%) | 1053.424 (40.61%) | 990.794 (38.2%) | |
jdk-17.0.7 | 2577.714 | 829.781 (32.19%) | 1106.165 (42.91%) | 1001.714 (38.86%) | |
graalvm_17.0.7+8.1 | 2712.799 | 980.767 (36.15%) | 1050.036 (38.71%) | 1039.594 (38.32%) |
这个场景是将JSON格式字符串反序列化为JSONObject,这也是一个最常见的场景之一,这个场景在fastjson中的代码如下:
String str = "...";
JSONObject jsonObject = JSON.parseJSONObject(str);
fastjson2在这个场景也表现了远超fastjson1/jackson/gson的性能。 在不同的环境中,fastjson1和jackson都只能相当于fastjson2性能的40%~60%,gson则更差一些。
性能排序如下:
// aliyun_ecs.g8i.large
fastjson2 > fastjson1 > jackson > gson
jdk8 100% 54.31% 53.78% 38.68%
jdk11 100% 51.64% 51.53% 40.37%
jdk17 100% 50.91% 47.02% 33.00%
下面是不同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.g8i.large | jdk1.8.0_371 | 2157.731 | 1171.904 (54.31%) | 1160.387 (53.78%) | 834.626 (38.68%) |
jdk-11.0.19 | 1967.972 | 1016.21 (51.64%) | 1014.106 (51.53%) | 794.442 (40.37%) | |
jdk-17.0.7 | 2460.387 | 1252.679 (50.91%) | 1156.897 (47.02%) | 811.927 (33%) | |
graalvm_17.0.7+8.1 | 2494.678 | 1493.373 (59.86%) | 1213.447 (48.64%) | 1074.36 (43.07%) | |
aliyun_ecs.g8y.large | jdk1.8.0_371 | 2544.851 | 1335.47 (52.48%) | 1169.094 (45.94%) | 1075.553 (42.26%) |
jdk-11.0.19 | 2831.14 | 1352.26 (47.76%) | 1259.093 (44.47%) | 1127.018 (39.81%) | |
jdk-17.0.7 | 2821.527 | 1434.44 (50.84%) | 1369.809 (48.55%) | 1129.4 (40.03%) | |
graalvm_17.0.7+8.1 | 3211.594 | 2145.957 (66.82%) | 1553.492 (48.37%) | 1381.737 (43.02%) | |
orangepi5p | jdk1.8.0_371 | 2081.1 | 1066.732 (51.26%) | 1150.45 (55.28%) | 892.438 (42.88%) |
jdk-11.0.19 | 2174.288 | 1061.327 (48.81%) | 1103.669 (50.76%) | 883.381 (40.63%) | |
jdk-17.0.7 | 2228.951 | 1304.163 (58.51%) | 1198.572 (53.77%) | 874.087 (39.22%) | |
graalvm_17.0.7+8.1 | 2394.753 | 1683.816 (70.31%) | 1270.827 (53.07%) | 999.579 (41.74%) |
这个是将UTF8格式的byte数组反序列化为Java对象,这个场景在缓存和RPC场景中常用。
这个场景在fastjson中的代码如下:
byte[] utf8Bytes = ...;
Bean bean = JSON.parseJSONObject(utf8Bytes, Bean.class);
这个场景fastjson2同样表现出了卓越的性能;在JDK11下,fastjson1和jackson的性能分别之后fastjson2的72.39%和45.97%; gson不直接支持输入utf8Bytes,需要先构造字符串,性能只有fastjson2的34.14%。
性能排序如下:
// aliyun_ecs.g8i.large
fastjson2 > fastjson1 > jackson > gson
jdk8 100% 76.55% 49.58% 37.17%
jdk11 100% 72.39% 45.97% 41.59%
jdk17 100% 70.86% 36.05% 33.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.g8i.large | jdk1.8.0_371 | 2416.504 | 1849.718 (76.55%) | 1198.099 (49.58%) | 898.149 (37.17%) |
jdk-11.0.19 | 2295.677 | 1661.76 (72.39%) | 1055.356 (45.97%) | 954.814 (41.59%) | |
jdk-17.0.7 | 2927.294 | 2074.57 (70.87%) | 1055.151 (36.05%) | 985.241 (33.66%) | |
graalvm_17.0.7+8.1 | 2982.08 | 2482.913 (83.26%) | 1184.176 (39.71%) | 1018.019 (34.14%) | |
aliyun_ecs.g8y.large | jdk1.8.0_371 | 3566.348 | 2660.834 (74.61%) | 1544.212 (43.3%) | 1298.701 (36.42%) |
jdk-11.0.19 | 4219.927 | 2479.671 (58.76%) | 1507.776 (35.73%) | 1342.897 (31.82%) | |
jdk-17.0.7 | 4249.983 | 3111.088 (73.2%) | 1475.474 (34.72%) | 1338.74 (31.5%) | |
graalvm_17.0.7+8.1 | 4686.092 | 3145.142 (67.12%) | 1366.381 (29.16%) | 1484.494 (31.68%) | |
orangepi5p | jdk1.8.0_371 | 2798.083 | 2052.691 (73.36%) | 1386.798 (49.56%) | 932.633 (33.33%) |
jdk-11.0.19 | 3164.784 | 2041.79 (64.52%) | 1294.929 (40.92%) | 1010.805 (31.94%) | |
jdk-17.0.7 | 3278.378 | 2659.782 (81.13%) | 1323.835 (40.38%) | 1043.902 (31.84%) | |
graalvm_17.0.7+8.1 | 3652.372 | 2285.648 (62.58%) | 1218.417 (33.36%) | 1096.793 (30.03%) |
这个是Java对象序列化成字符串, 这个是序列化最常用的场景之一。这个场景在fastjson中的代码如下:
Bean bean = ...;
String str = JSON.toJSONString(bean);
在这个最常用的序列化场景,fastjson2表现出远超fastjson1/jackson/gson的性能;这个场景gson表现很差,只有fastjson2的20~30%。
性能排序如下:
// aliyun_ecs.g8i.large
fastjson2 > jackson > fastjson1 > gson
jdk8 100% 66.86% 46.91% 29.33%
jdk11 100% 64.27% 46.63% 25.89%
jdk17 100% 58.23% 41.18% 19.61%
下面是不同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.g8i.large | jdk1.8.0_371 | 3351.555 | 1572.199 (46.91%) | 2241.006 (66.86%) | 982.929 (29.33%) |
jdk-11.0.19 | 3050.54 | 1422.379 (46.63%) | 1960.731 (64.27%) | 789.742 (25.89%) | |
jdk-17.0.7 | 3663.698 | 1508.58 (41.18%) | 2133.552 (58.23%) | 718.56 (19.61%) | |
graalvm_17.0.7+8.1 | 5020.114 | 1745.964 (34.78%) | 2506.563 (49.93%) | 687.009 (13.69%) | |
aliyun_ecs.g8y.large | jdk1.8.0_371 | 4600.757 | 2073.222 (45.06%) | 2471.014 (53.71%) | 1338.269 (29.09%) |
jdk-11.0.19 | 5150.534 | 1932.703 (37.52%) | 2547.575 (49.46%) | 1105.371 (21.46%) | |
jdk-17.0.7 | 5344.878 | 2149.421 (40.21%) | 2765.983 (51.75%) | 844.873 (15.81%) | |
graalvm_17.0.7+8.1 | 6792.175 | 3506.425 (51.62%) | 3331.736 (49.05%) | 875.97 (12.9%) | |
orangepi5p | jdk1.8.0_371 | 3914.563 | 3192.798 (81.56%) | 1996.57 (51%) | 955.556 (24.41%) |
jdk-11.0.19 | 4420.479 | 1460.266 (33.03%) | 2093.505 (47.36%) | 920.034 (20.81%) | |
jdk-17.0.7 | 4504.858 | 1640.45 (36.42%) | 2146.788 (47.65%) | 832.334 (18.48%) | |
graalvm_17.0.7+8.1 | 4853.059 | 1952.938 (40.24%) | 2304.794 (47.49%) | 798.729 (16.46%) |
这个是Java对象序列化成UTF格式的byte数组, 这个是最常用的场景之一,在缓存和RPC场景常用。gson不直接支持,需要先序列化为String再转换为UTF8格式的byte数组。
这个场景在fastjson中的代码如下:
Bean bean = ...;
byte[] utf8Bytes = JSON.toJSONBytes(bean);
在这个最常用的序列化场景,fastjson2表现出远超fastjson1/jackson/gson的性能;这个场景gson表现很差。
性能排序如下:
// aliyun_ecs.g8i.large
fastjson2 > jackson > fastjson1 > gson
jdk8 100% 61.94% 44.83% 28.00%
jdk11 100% 55.59% 47.40% 22.91%
jdk17 100% 47.99% 32.03% 17.20%
下面是不同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.g8i.large | jdk1.8.0_371 | 3117.898 | 1397.729 (44.83%) | 1931.227 (61.94%) | 872.899 (28%) |
jdk-11.0.19 | 3290.208 | 1559.448 (47.4%) | 1829.172 (55.59%) | 753.726 (22.91%) | |
jdk-17.0.7 | 4094.515 | 1311.418 (32.03%) | 1964.922 (47.99%) | 704.437 (17.2%) | |
graalvm_17.0.7+8.1 | 5293.463 | 1574.744 (29.75%) | 2496.69 (47.17%) | 692.987 (13.09%) | |
aliyun_ecs.g8y.large | jdk1.8.0_371 | 5066.945 | 1877.169 (37.05%) | 2531.139 (49.95%) | 1165.513 (23%) |
jdk-11.0.19 | 5395.098 | 2641.487 (48.96%) | 2402.697 (44.53%) | 1128.482 (20.92%) | |
jdk-17.0.7 | 5484.846 | 1934.638 (35.27%) | 2702.184 (49.27%) | 816.215 (14.88%) | |
graalvm_17.0.7+8.1 | 7678.186 | 2230.843 (29.05%) | 3437.981 (44.78%) | 832.257 (10.84%) | |
orangepi5p | jdk1.8.0_371 | 4335.683 | 1421.801 (32.79%) | 2099.996 (48.44%) | 805.302 (18.57%) |
jdk-11.0.19 | 4675.018 | 1355.289 (28.99%) | 1887.46 (40.37%) | 900.066 (19.25%) | |
jdk-17.0.7 | 4850.415 | 1419.481 (29.27%) | 2137.183 (44.06%) | 754.629 (15.56%) | |
graalvm_17.0.7+8.1 | 5873.62 | 1975.705 (33.64%) | 2479.081 (42.21%) | 798.512 (13.59%) |
这个场景是JSONObject序列化成字符串, 这个是序列化最常用的场景之一。这个场景在fastjson中的代码如下:
JSONObject jsonObject = ...;
String str = jsonObject.toJSONString();
在这个最常用的序列化场景,fastjson2表现出远超fastjson1/jackson/gson的性能;这个场景gson表现很差,只有fastjson2的1/3
性能排序如下:
// aliyun_ecs.g8i.large
fastjson2 > jackson > fastjson1 > gson
jdk8 100% 60.01% 60.00% 33.35%
jdk11 100% 71.79% 70.46% 32.87%
jdk17 100% 51.64% 59.24% 23.41%
aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
---|---|---|---|---|---|
aliyun_ecs.g8i.large | jdk1.8.0_371 | 3261.752 | 1957.175 (60%) | 2120.432 (65.01%) | 1087.704 (33.35%) |
jdk-11.0.19 | 2578.451 | 1816.697 (70.46%) | 1850.786 (71.78%) | 847.599 (32.87%) | |
jdk-17.0.7 | 3121.17 | 1849.111 (59.24%) | 1611.837 (51.64%) | 730.516 (23.41%) | |
graalvm_17.0.7+8.1 | 3445.437 | 2106.462 (61.14%) | 2172.493 (63.05%) | 731.296 (21.23%) | |
aliyun_ecs.g8y.large | jdk1.8.0_371 | 3734.306 | 2265.691 (60.67%) | 2534.349 (67.87%) | 1614.077 (43.22%) |
jdk-11.0.19 | 3813.869 | 2424.057 (63.56%) | 2559.903 (67.12%) | 1365.337 (35.8%) | |
jdk-17.0.7 | 4778.902 | 2268.404 (47.47%) | 2507.172 (52.46%) | 877.351 (18.36%) | |
graalvm_17.0.7+8.1 | 4529.66 | 3241.686 (71.57%) | 3095.552 (68.34%) | 902.854 (19.93%) | |
orangepi5p | jdk1.8.0_371 | 2686.429 | 1767.555 (65.8%) | 2019.632 (75.18%) | 1020.227 (37.98%) |
jdk-11.0.19 | 2689.171 | 1783.27 (66.31%) | 2091.617 (77.78%) | 1033.408 (38.43%) | |
jdk-17.0.7 | 3132.018 | 1797.459 (57.39%) | 2089.26 (66.71%) | 861.928 (27.52%) | |
graalvm_17.0.7+8.1 | 3264.53 | 2195.442 (67.25%) | 2329.688 (71.36%) | 849.392 (26.02%) |
这个场景是将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_ecs.g8i.large
fastjson2_jsonb > hessian > javaSerialize
jdk8 100% 25.87% 15.56%
jdk11 100% 28.08% 17.61%
jdk17 100% 24.30% 15.89%
下面是不同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.g8i.large | jdk1.8.0_371 | 3361.737 | 869.574 (25.87%) | 523.171 (15.56%) |
jdk-11.0.19 | 2939.23 | 825.242 (28.08%) | 517.6 (17.61%) | |
jdk-17.0.7 | 3369.112 | 818.714 (24.3%) | 535.34 (15.89%) | |
graalvm_17.0.7+8.1 | 4690.64 | 1256.73 (26.79%) | 572.517 (12.21%) | |
aliyun_ecs.g8y.large | jdk1.8.0_371 | 4575.932 | 1189.073 (25.99%) | 825.689 (18.04%) |
jdk-11.0.19 | 4540.034 | 1029.985 (22.69%) | 820.761 (18.08%) | |
jdk-17.0.7 | 4404.005 | 1243.94 (28.25%) | 817.773 (18.57%) | |
graalvm_17.0.7+8.1 | 6289.787 | 1302.702 (20.71%) | 817.432 (13%) | |
orangepi5p | jdk1.8.0_371 | 3584.42 | 682.634 (19.04%) | 626.146 (17.47%) |
jdk-11.0.19 | 3645.459 | 683.877 (18.76%) | 651.808 (17.88%) | |
jdk-17.0.7 | 3490.94 | 692.969 (19.85%) | 650.79 (18.64%) | |
graalvm_17.0.7+8.1 | 4493.808 | 704.132 (15.67%) | 601.961 (13.4%) |
这个场景是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_ecs.g8i.large
fastjson2_jsonb > hessian > javaSerialize
jdk8 100% 17.82% 3.08%
jdk11 100% 14.25% 2.68%
jdk17 100% 13.54% 2.72%
下面是不同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.g8i.large | jdk1.8.0_371 | 3794.594 | 676.044 (17.82%) | 117.058 (3.08%) |
jdk-11.0.19 | 4339.484 | 618.233 (14.25%) | 116.458 (2.68%) | |
jdk-17.0.7 | 4779.001 | 647.288 (13.54%) | 130.006 (2.72%) | |
graalvm_17.0.7+8.1 | 5181.598 | 794.567 (15.33%) | 141.942 (2.74%) | |
aliyun_ecs.g8y.large | jdk1.8.0_371 | 5430.68 | 331.514 (6.1%) | 162.923 (3%) |
jdk-11.0.19 | 5729.123 | 441.793 (7.71%) | 156.723 (2.74%) | |
jdk-17.0.7 | 5907.579 | 393.633 (6.66%) | 161.934 (2.74%) | |
graalvm_17.0.7+8.1 | 6358.521 | 541.31 (8.51%) | 170.87 (2.69%) | |
orangepi5p | jdk1.8.0_371 | 3795.223 | 182.861 (4.82%) | 136.707 (3.6%) |
jdk-11.0.19 | 4189.609 | 184.741 (4.41%) | 128.911 (3.08%) | |
jdk-17.0.7 | 4261.107 | 192.88 (4.53%) | 144.517 (3.39%) | |
graalvm_17.0.7+8.1 | 4998.054 | 239.668 (4.8%) | 145.492 (2.91%) |