4.10 性能测试对比
About 612 wordsAbout 2 min
2021-03-27
4.10 性能测试对比
最新测试对比
https://gitee.com/xiandafu/beetl/tree/master/template-benchmark
使用 JMH ,测试结果更权威
还有些编译成class的模板引擎新性能非常好,但没有入选,因为他们语法更简单,且模板编译成class,功能有局限
- te4j https://github.com/whilein/te4j 长时间不维护
- jte https://jte.gg/ 推荐
- httl http://httl.github.io/en/ 长时间不维护
运行
mvn clean install
- 运行
java -jar target/benchmarks.jar
- 单独运行 `java -jar target/benchmarks.jar Beetl Freemarker
目前结果(2024-4-12)越高越好
2线程并发
Benchmark Mode Cnt Score Error Units
Beetl.benchmark thrpt 5 109547.863 ± 17161.576 ops/s
BeetlByte.benchmark thrpt 5 237799.769 ± 5904.514 ops/s
Enjoy.benchmark thrpt 5 99695.440 ± 14083.595 ops/s
EnjoyByte.benchmark thrpt 5 223874.001 ± 7265.307 ops/s
Freemarker.benchmark thrpt 5 41452.634 ± 15917.119 ops/s
Handlebars.benchmark thrpt 5 40360.198 ± 24345.048 ops/s
Rocker.benchmark thrpt 5 63657.017 ± 4653.265 ops/s
Thymeleaf.benchmark thrpt 5 6457.169 ± 272.613 ops/s
Velocity.benchmark thrpt 5 8024.042 ± 2097.396 ops/s
注意,最新测试包含了二进制直接输出,BeetlByte.benchmark,EnjoyByte.benchmark支持且性能非常好
总结
- 对比其他流行模板引擎Beetl性能非常优秀, https://www.kancloud.cn/xiandafu/javamicrotuning。
- Thymeleaf 和 Velocity 性能是最糟糕的,这个测试毫无疑问又一次证明
- 并发测试考虑到机器性能原因,有可能不准,供参考。可以查看单线程性能测试结果,这能体现模板引擎的能力
过往对比1
测试用例一 https://github.com/javamonkey/ebm
过往对比2
测试用例二 http://git.oschina.net/kiang/teb
过往对比3
https://github.com/javamonkey/template-benchmark
Benchmark | version | Threads | Samples | Score | Score Error (99.9%) | Unit |
---|---|---|---|---|---|---|
Beetl | 2.7 | 1 | 50 | 42125.112914 | 3512.147131 | ops/s |
Freemarker | 2.3 | 1 | 50 | 13099.139808 | 339.612022 | ops/s |
Handlebars | 4.0 | 1 | 50 | 15808.044125 | 235.109622 | ops/s |
Mustache | 0.9 | 1 | 50 | 17961.391809 | 158.524109 | ops/s |
Rocker | 0.1 | 1 | 50 | 33631.370722 | 417.915637 | ops/s |
Thymeleaf | 3.0 | 1 | 50 | 4625.981276 | 67.313609 | ops/s |
Score得分越高表示模板引擎每秒处理量越大性能越好
这个性能测试基本上结合了国内外的模板引擎,随着JDK版本的升级,JDK8提高了反射能力,减少了和Freemarker等模板引擎的性能差距,但Beetl依旧以3倍以上的性能优势秒杀Freemarker。