# template-benchmark **Repository Path**: haroldyong/template-benchmark ## Basic Information - **Project Name**: template-benchmark - **Description**: 国内外模板引擎性能测试,包含Beetl,Freemaker,Thymleaf,Rocker等,改编自rocker的测试 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 5 - **Created**: 2020-04-02 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 模板引擎性能测试 ## 使用 JMH ,测试结果更权威 * [Freemarker](http://freemarker.org/) * [Mustache](https://github.com/spullara/mustache.java) * [Pebble](http://www.mitchellbosecke.com/pebble) * [Rocker](https://github.com/fizzed/rocker) * [Thymeleaf](http://www.thymeleaf.org/) * [Trimou](http://trimou.org/) * [Velocity](http://velocity.apache.org/) * [Beetl](http://ibeetl.com/) * [JFinal](http://jfinal.com/) ## 运行 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提供字节流操作,同时接近真实运行时候性能 ### 总结 * Beetl在任何模式性下能都是最好的,靠的的是微优化技巧。可以参考https://item.jd.com/12742086.html了解Java性能优化 * Thymeleaf 性能是最糟糕的,这个测试毫无疑问又一次证明 * Velocity在并发下有问题,这个测试也是证明此问题 * JFinal模板引擎6月份后(一个好玩的故事),又再次优化,性能接近Beetl了,希望它能借鉴更多Beetl优化技巧,以及不要"吹牛",糊弄刚入行的人 * 并发测试考虑到机器性能原因,有可能不准,供参考。可以查看单线程性能测试结果,这能体现模板引擎的能力 ## 如何加入 需要满足ExpectedOutputTest单元测试,需要满足3种输出类型(如果不满足,抛出异常即可) ## 测试说明 测试源码来自 https://github.com/fizzed/template-benchmark 做了一点调整,支持三种输出类型