1 Star 0 Fork 5

cgb-study / template-benchmark

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

模板引擎性能测试

使用 JMH ,测试结果更权威

运行

  1. mvn clean install
  2. 运行 java -jar target/benchmarks.jar
  3. 单独运行 java -jar target/benchmarks.jar Beetl

目前结果(2019-12-29)

单线程性能测试

Benchmark             (outputType)   Mode  Cnt      Score      Error  Units
Beetl.benchmark                  1  thrpt   10  86499.426 ±  819.202  ops/s
Beetl.benchmark                  2  thrpt   10  53523.776 ±  365.894  ops/s
Beetl.benchmark                  3  thrpt   10  97586.864 ±  947.663  ops/s
Freemarker.benchmark             1  thrpt   10  23655.886 ±  118.846  ops/s
Freemarker.benchmark             2  thrpt   10  19697.882 ±  115.250  ops/s
Handlebars.benchmark             1  thrpt   10  22828.835 ±  220.474  ops/s
Handlebars.benchmark             2  thrpt   10  22885.014 ±  194.975  ops/s
JFinal.benchmark                 1  thrpt   10  74501.952 ±  840.441  ops/s
JFinal.benchmark                 2  thrpt   10  49252.672 ±  284.398  ops/s
JFinal.benchmark                 3  thrpt   10  88973.531 ± 1409.273  ops/s
Rocker.benchmark                 1  thrpt   10  50437.848 ±  475.690  ops/s
Rocker.benchmark                 2  thrpt   10  31419.460 ±   95.329  ops/s
Rocker.benchmark                 3  thrpt   10  88109.687 ±  645.572  ops/s
Thymeleaf.benchmark              1  thrpt   10   7199.343 ±   77.446  ops/s
Thymeleaf.benchmark              2  thrpt   10   5481.519 ±   44.072  ops/s
Velocity.benchmark               1  thrpt   10   7928.416 ±  126.237  ops/s
Velocity.benchmark               2  thrpt   10   7110.021 ±   99.296  ops/s

8个并发程性能测试

Benchmark             (outputType)   Mode  Cnt       Score      Error  Units
Beetl.benchmark                  1  thrpt   10  399650.018 ± 5267.017  ops/s
Beetl.benchmark                  2  thrpt   10  227805.586 ± 1376.397  ops/s
Beetl.benchmark                  3  thrpt   10  389779.874 ± 5796.863  ops/s
Freemarker.benchmark             1  thrpt   10  120212.045 ± 1406.250  ops/s
Freemarker.benchmark             2  thrpt   10   99093.944 ±  482.070  ops/s
Handlebars.benchmark             1  thrpt   10  112414.319 ±  592.529  ops/s
Handlebars.benchmark             2  thrpt   10  114264.442 ±  850.765  ops/s
JFinal.benchmark                 1  thrpt   10  299089.547 ± 5139.087  ops/s
JFinal.benchmark                 2  thrpt   10  205477.432 ± 3533.227  ops/s
JFinal.benchmark                 3  thrpt   10  371156.576 ± 5766.780  ops/s
Rocker.benchmark                 1  thrpt   10  224646.481 ± 1980.803  ops/s
Rocker.benchmark                 2  thrpt   10  137806.640 ± 2088.926  ops/s
Rocker.benchmark                 3  thrpt   10  373242.178 ± 3287.081  ops/s
Thymeleaf.benchmark              1  thrpt   10   33877.492 ±  936.758  ops/s
Thymeleaf.benchmark              2  thrpt   10   24462.026 ±  923.647  ops/s
Velocity.benchmark               1  thrpt   10   32304.782 ±  790.253  ops/s
Velocity.benchmark               2  thrpt   10   29537.516 ±  845.503  ops/s

输出类型

  • 1 String:这个同"https://github.com/fizzed/template-benchmark"测试结果。
  • 2 字符流:模板渲染后输出到Writer,通常MVC会输出到字符流。
  • 3 字节流:模板渲染后输出到OutputStream,注意,只有Beetl和Rocker,JFinal提供字节流操作,同时接近真实运行时候性能

需要修改BaseBenchmark的outputType,更改如下,则同时测试三种场景

@Param({"1","2","3"})
int  outputType;

总结

  • Beetl在任何模式性下能都是最好的,靠的的是微优化技巧。可以参考https://item.jd.com/12742086.html了解Java性能优化
  • Thymeleaf 性能是最糟糕的,这个测试毫无疑问又一次证明
  • Velocity在并发下有问题,这个测试也是证明此问题
  • 并发测试考虑到机器性能原因,有可能不准,供参考。可以查看单线程性能测试结果,这能体现模板引擎的能力

如何加入

需要满足ExpectedOutputTest单元测试,需要满足3种输出类型(如果不满足,抛出异常即可)

测试说明

测试源码来自 https://github.com/fizzed/template-benchmark 做了一点调整,支持三种输出类型

空文件

简介

国内外模板引擎性能测试,包含Beetl,Freemaker,Thymleaf,Rocker等,改编自rocker的测试 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/cgb-study/template-benchmark.git
git@gitee.com:cgb-study/template-benchmark.git
cgb-study
template-benchmark
template-benchmark
master

搜索帮助