高性能java库和热门库的评测pk
高性能java库wast,性能炸裂!
:听说这个java库的性能是很高的?:是的!:有多高?:大概三四楼那么高啦!
github源码地址:
https://github.com/wycst/wast
测试代码地址:
https://github.com/wycst/wast-jmh-test
<dependency> <groupId>io.github.wycst</groupId> <artifactId>wast</artifactId> <version>0.0.3</version></dependency>
测试环境
- 服务器: window10 32g i5 ssd
- ide: idea2020.3
版本信息
- jmh.v1.3.5
- wast.v0.0.3
- fastjson.v1.2.83
- fastjson2.v2.0.6
- jackson.v.2.9.9.3
- spel.v5.3.9
- snakeyaml.v1.29
8 8 1.35 5.3.9 1.2.83 2.0.6 1.29 2.9.9.3 io.github.wycst wast 0.0.3 com.alibaba.fastjson2 fastjson2 ${fastjson2.version} com.alibaba fastjson ${fastjson1.version} com.fasterxml.jackson.core jackson-databind ${jackson.version} org.springframework spring-expression ${spring.version} org.yaml snakeyaml ${snakeyaml-version} org.openjdk.jmh jmh-core ${jmh.version} org.openjdk.jmh jmh-generator-annprocess ${jmh.version}
JSON篇
- 反序列化 - 简单实体bean的解析(ops/ms)
Benchmark Mode Cnt Score Error UnitsSimpleBeanTest.fastjson1 thrpt 5 295.223 ± 25.515 ops/msSimpleBeanTest.fastjson2 thrpt 5 785.447 ± 14.362 ops/msSimpleBeanTest.jackson thrpt 5 474.894 ± 26.205 ops/msSimpleBeanTest.wastjson thrpt 5 1189.094 ± 60.265 ops/ms
测试类: https://github.com/wycst/wast-jmh-test/blob/main/src/main/java/com/jmh/test/json/bean/SimpleBeanTest.java
测试结果: wastjson >> fastjson2 > jackson > fastjson1
- 反序列化 - 小文本解析测试(ops/ms)
Benchmark Mode Cnt Score Error UnitsSmallTextParseTest.fastjson1 thrpt 5 1479.282 ± 17.987 ops/msSmallTextParseTest.fastjson2 thrpt 5 2401.221 ± 77.762 ops/msSmallTextParseTest.jackson thrpt 5 1427.027 ± 54.206 ops/msSmallTextParseTest.wastjson thrpt 5 2199.300 ± 30.759 ops/ms
测试类: https://github.com/wycst/wast-jmh-test/blob/main/src/main/java/com/jmh/test/json/bean/SmallTextParseTest.java
测试结果: fastjson2 > wastjson > fastjson1 > jackson
- 反序列化 - 中长文本测试(175kb)(ops/s)
Benchmark Mode Cnt Score Error UnitsLongTextParseTest.escapeFastjson1 thrpt 5 2403.397 ± 67.258 ops/sLongTextParseTest.escapeFastjson2 thrpt 5 2470.036 ± 41.012 ops/sLongTextParseTest.escapeJackson thrpt 5 2264.022 ± 63.137 ops/sLongTextParseTest.escapeWastjson thrpt 5 9946.527 ± 249.772 ops/sLongTextParseTest.escapePrettyFastjson thrpt 5 2631.821 ± 40.613 ops/sLongTextParseTest.escapePrettyFastjson2 thrpt 5 2433.739 ± 40.984 ops/sLongTextParseTest.escapePrettyJackson thrpt 5 1568.147 ± 103.349 ops/sLongTextParseTest.escapePrettyWastjson thrpt 5 9961.827 ± 551.414 ops/sLongTextParseTest.fastjson1thrpt 5 5118.035 ± 112.711 ops/sLongTextParseTest.fastjson2thrpt 5 6850.418 ± 147.904 ops/sLongTextParseTest.jackson thrpt 5 2936.602 ± 39.819 ops/sLongTextParseTest.wastjson thrpt 5 9468.415 ± 71.767 ops/sLongTextParseTest.prettyFastjson1 thrpt 5 5118.231 ± 31.292 ops/sLongTextParseTest.prettyFastjson2 thrpt 5 6830.779 ± 46.084 ops/sLongTextParseTest.prettyJackson thrpt 5 2910.411 ± 37.276 ops/sLongTextParseTest.prettyWastjson thrpt 5 9459.602 ± 210.523 ops/s
测试类: https://github.com/wycst/wast-jmh-test/blob/main/src/main/java/com/jmh/test/json/bean/LongTextParseTest.java
测试结果: wastjson >> fastjson2 > fastjson1 > jackson
- 反序列化 - 中文本测试(515kb)(ops/s)
Benchmark Mode Cnt Score Error UnitsLongTextParseTest2.fastjson1 thrpt 5 502.565 ± 4.324 ops/sLongTextParseTest2.fastjson2 thrpt 5 528.788 ± 4.027 ops/sLongTextParseTest2.jackson thrpt 5 596.762 ± 32.091 ops/sLongTextParseTest2.wastjson thrpt 5 569.860 ± 5.274 ops/s
测试类: https://github.com/wycst/wast-jmh-test/blob/main/src/main/java/com/jmh/test/json/bean/LongTextParseTest2.java
测试结果: jackson > wastjson > fastjson2 > fastjson1
- 反序列化 - 超大长文本测试(180mb)(ops/min)
Benchmark Mode Cnt Score Error UnitsSuperLongText.fastjson thrpt 5 25.945 ± 10.596 ops/minSuperLongText.fastjson2 thrpt 5 20.453 ± 17.898 ops/minSuperLongText.jackson thrpt 5 21.170 ± 0.432 ops/minSuperLongText.wastjson thrpt 5 49.315 ± 12.184 ops/min
测试类: https://github.com/wycst/wast-jmh-test/blob/main/src/main/java/com/jmh/test/json/bean/SuperLongText.java
测试结果: wastjson >> fastjson > jackson > fastjson2
- 通过流读取超大长JSON文本测试(180mb)(ops/min)
Benchmark Mode Cnt Score Error UnitsReadInputStreamTest.jackson thrpt 5 17.911 ± 3.584 ops/minReadInputStreamTest.wastjson thrpt 5 27.118 ± 10.143 ops/min
测试类: https://github.com/wycst/wast-jmh-test/blob/main/src/main/java/com/jmh/test/json/bean/ReadInputStreamTest.java
测试结果: wastjson >> jackson
(fastjson完全没法读取超大文本流,退出此轮评测)
- 序列化 - 中长文本(ops/ms)
Benchmark Mode Cnt Score Error UnitsWriteTest.escapeFastjson thrpt 5 248.960 ± 2.526 ops/msWriteTest.escapeFastjson2 thrpt 5 134.715 ± 0.727 ops/msWriteTest.escapeJackson thrpt 5 285.107 ± 4.332 ops/msWriteTest.escapeWastjson thrpt 5 365.724 ± 16.478 ops/msWriteTest.fastjson thrpt 5 528.649 ± 24.377 ops/msWriteTest.fastjson2 thrpt 5 372.189 ± 3.944 ops/msWriteTest.jackson thrpt 5 329.733 ± 2.537 ops/msWriteTest.wastjson thrpt 5 571.830 ± 1.658 ops/ms
测试类: https://github.com/wycst/wast-jmh-test/blob/main/src/main/java/com/jmh/test/json/bean/WriteTest.java
测试结果:
常规文本: wastjson > fastjson > fastjson2 > jackson
转义文本: wastjson > jackson > fastjson > fastjson2
- fastjson2新特性JSONPath的pk (ops/ms)
Benchmark Mode Cnt Score Error UnitsJSONPathTest.fastjsonReaderAuthors thrpt 5 454.894 ± 12.225 ops/msJSONPathTest.fastjsonReaderPrices thrpt 5 455.360 ± 2.692 ops/msJSONPathTest.fastjsonReaderTop2Author thrpt 5 555.557 ± 23.740 ops/msJSONPathTest.wastAuthors thrpt 5 801.320 ± 56.132 ops/msJSONPathTest.wastPrices thrpt 5 908.480 ± 26.998 ops/msJSONPathTest.wastTop2Authors thrpt 5 1451.135 ± 19.843 ops/ms
测试类: https://github.com/wycst/wast-jmh-test/blob/main/src/main/java/com/jmh/test/json/path/JSONPathTest.java
测试结果:wastjson(JSONNode) >> fastjson2
表达式引擎
pk对象spel(mvel2, ognl, Fel等库性能和spel差距有点大就不考虑加入评测)
不考虑编译模式(将表达式编译为字节码),没啥价值可比。
Benchmark Mode Cnt Score Error UnitsExpressionTest.spelDirectDynamicExpr thrpt 5 3636.816 ± 119.516 ops/sExpressionTest.spelDirectStaticExpr thrpt 5 3647.830 ± 103.602 ops/sExpressionTest.spelParseDynamicExpr thrpt 5 1638805.101 ± 261375.252 ops/sExpressionTest.wastDirectDynamicExpr thrpt 5 4519.986 ± 257.351 ops/sExpressionTest.wastDirectStaticExpr thrpt 5 4563.065 ± 68.228 ops/sExpressionTest.wastParseDynamicExpr thrpt 5 3172853.345 ± 355515.730 ops/s
测试类: https://github.com/wycst/wast-jmh-test/blob/main/src/main/java/com/jmh/test/expression/ExpressionTest.java
测试结果:wast > spel
yaml
pk对象org.snakeyaml库(暂时未发现有其他的yaml库)
Benchmark Mode Cnt Score Error UnitsYamlTest.snakeyaml thrpt 5 26.687 ± 0.832 ops/msYamlTest.wastYaml thrpt 5 548.392 ± 2.784 ops/ms
测试类: https://github.com/wycst/wast-jmh-test/blob/main/src/main/java/com/jmh/test/yaml/YamlTest.java
测试结果:wast >> spel
开发者涨薪指南
48位大咖的思考法则、工作方式、逻辑体系央视天气网