在某个“新模板引擎”的基准测试增加Beetl,测试结果如下,可以看到Beetl还是很领先,每秒渲染80685次(我的机器是Mac Pro,Core I7)
Benchmark Mode Cnt Score Error Units
Beetl.benchmark thrpt 10 80685.217 ± 3056.314 ops/s
Enjoy.benchmark thrpt 10 71429.555 ± 626.639 ops/s
Freemarker.benchmark thrpt 10 22262.620 ± 917.084 ops/s
Handlebars.benchmark thrpt 10 23077.234 ± 271.438 ops/s
Mustache.benchmark thrpt 10 25899.922 ± 235.957 ops/s
Pebble.benchmark thrpt 10 43756.295 ± 1816.826 ops/s
Rocker.benchmark thrpt 10 49089.556 ± 693.635 ops/s
Thymeleaf.benchmark thrpt 10 6998.717 ± 160.461 ops/s
Trimou.benchmark thrpt 10 28561.924 ± 759.969 ops/s
Velocity.benchmark thrpt 10 25087.417 ± 251.709 ops/s
最糟糕的依然是Thymeleaf,每秒渲染6998次。Beetl性能是它的12倍
Beetl很长时间没有在考虑性能优化方面的再升级了,这方面技术都是在大约5年前的技术,这些性能技术积累更来自于10年前,我还还写了一本书《Java系统性能优化实战》,把这些经验以及国外性能优秀工具的优化经验都通过代码说出来了
Beetl3升级主要方向还是朝着如何更方便用户使用和二次开发,比如不仅仅支持自定义定界符和占位符,还支持再定义一对。比如,支持很方便的重写语法树从而支持用户想要的特性等等。Beetl3已经朝着平台化发展,希望有人一想到模板设计模式,就能想到用Beetl完成。
如下是日志输出,如果你想读懂,你也可以购买我的书学习看看Java性能怎么玩
>java -jar target/benchmarks.jar
# JMH 1.11.2 (released 1512 days ago, please consider updating!)
# VM version: JDK 1.8.0_231, VM 25.231-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: 7 iterations, 1 s each
# Measurement: 10 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.mitchellbosecke.benchmark.Beetl.benchmark
# Run progress: 0.00% complete, ETA 00:02:50
# Fork: 1 of 1
# Warmup Iteration 1: 51114.962 ops/s
# Warmup Iteration 2: 68838.051 ops/s
# Warmup Iteration 3: 80548.756 ops/s
# Warmup Iteration 4: 80455.776 ops/s
# Warmup Iteration 5: 82575.140 ops/s
# Warmup Iteration 6: 81991.678 ops/s
# Warmup Iteration 7: 81266.783 ops/s
Iteration 1: 82013.802 ops/s
Iteration 2: 82541.466 ops/s
Iteration 3: 80045.919 ops/s
Iteration 4: 79674.899 ops/s
Iteration 5: 78000.984 ops/s
Iteration 6: 76781.741 ops/s
Iteration 7: 82078.755 ops/s
Iteration 8: 81180.128 ops/s
Iteration 9: 81764.501 ops/s
Iteration 10: 82769.974 ops/s
Result "benchmark":
80685.217 ±(99.9%) 3056.314 ops/s [Average]
(min, avg, max) = (76781.741, 80685.217, 82769.974), stdev = 2021.562
CI (99.9%): [77628.903, 83741.531] (assumes normal distribution)
# JMH 1.11.2 (released 1512 days ago, please consider updating!)
# VM version: JDK 1.8.0_231, VM 25.231-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: 7 iterations, 1 s each
# Measurement: 10 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.mitchellbosecke.benchmark.Enjoy.benchmark
# Run progress: 10.00% complete, ETA 00:02:37
# Fork: 1 of 1
# Warmup Iteration 1: 31215.408 ops/s
# Warmup Iteration 2: 63274.067 ops/s
# Warmup Iteration 3: 59576.189 ops/s
# Warmup Iteration 4: 56251.571 ops/s
# Warmup Iteration 5: 67626.645 ops/s
# Warmup Iteration 6: 72074.793 ops/s
# Warmup Iteration 7: 71176.183 ops/s
Iteration 1: 70670.965 ops/s
Iteration 2: 71391.061 ops/s
Iteration 3: 71672.155 ops/s
Iteration 4: 70904.271 ops/s
Iteration 5: 71651.906 ops/s
Iteration 6: 71427.132 ops/s
Iteration 7: 71661.251 ops/s
Iteration 8: 72070.550 ops/s
Iteration 9: 71668.440 ops/s
Iteration 10: 71177.815 ops/s
Result "benchmark":
71429.555 ±(99.9%) 626.639 ops/s [Average]
(min, avg, max) = (70670.965, 71429.555, 72070.550), stdev = 414.483
CI (99.9%): [70802.916, 72056.193] (assumes normal distribution)
# JMH 1.11.2 (released 1512 days ago, please consider updating!)
# VM version: JDK 1.8.0_231, VM 25.231-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: 7 iterations, 1 s each
# Measurement: 10 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.mitchellbosecke.benchmark.Freemarker.benchmark
# Run progress: 20.00% complete, ETA 00:02:20
# Fork: 1 of 1
# Warmup Iteration 1: 12350.845 ops/s
# Warmup Iteration 2: 15622.818 ops/s
# Warmup Iteration 3: 15704.254 ops/s
# Warmup Iteration 4: 17695.744 ops/s
# Warmup Iteration 5: 23147.720 ops/s
# Warmup Iteration 6: 22273.775 ops/s
# Warmup Iteration 7: 21119.996 ops/s
Iteration 1: 22007.723 ops/s
Iteration 2: 23134.424 ops/s
Iteration 3: 22243.061 ops/s
Iteration 4: 22795.193 ops/s
Iteration 5: 23060.673 ops/s
Iteration 6: 22321.961 ops/s
Iteration 7: 21464.161 ops/s
Iteration 8: 22397.418 ops/s
Iteration 9: 21724.151 ops/s
Iteration 10: 21477.439 ops/s
Result "benchmark":
22262.620 ±(99.9%) 917.084 ops/s [Average]
(min, avg, max) = (21464.161, 22262.620, 23134.424), stdev = 606.594
CI (99.9%): [21345.537, 23179.704] (assumes normal distribution)
# JMH 1.11.2 (released 1512 days ago, please consider updating!)
# VM version: JDK 1.8.0_231, VM 25.231-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: 7 iterations, 1 s each
# Measurement: 10 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.mitchellbosecke.benchmark.Handlebars.benchmark
# Run progress: 30.00% complete, ETA 00:02:02
# Fork: 1 of 1
# Warmup Iteration 1: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
ANTLR Tool version 4.5.1 used for code generation does not match the current runtime version 4.7.2ANTLR Runtime version 4.5.1 used for parser compilation does not match the current runtime version 4.7.2ANTLR Tool version 4.5.1 used for code generation does not match the current runtime version 4.7.2ANTLR Runtime version 4.5.1 used for parser compilation does not match the current runtime version 4.7.213789.253 ops/s
# Warmup Iteration 2: 18012.201 ops/s
# Warmup Iteration 3: 22485.044 ops/s
# Warmup Iteration 4: 23362.141 ops/s
# Warmup Iteration 5: 23085.279 ops/s
# Warmup Iteration 6: 23253.656 ops/s
# Warmup Iteration 7: 23129.963 ops/s
Iteration 1: 23038.476 ops/s
Iteration 2: 23235.933 ops/s
Iteration 3: 23323.908 ops/s
Iteration 4: 23188.352 ops/s
Iteration 5: 22849.885 ops/s
Iteration 6: 23006.736 ops/s
Iteration 7: 22738.257 ops/s
Iteration 8: 23144.517 ops/s
Iteration 9: 23052.706 ops/s
Iteration 10: 23193.571 ops/s
Result "benchmark":
23077.234 ±(99.9%) 271.438 ops/s [Average]
(min, avg, max) = (22738.257, 23077.234, 23323.908), stdev = 179.539
CI (99.9%): [22805.797, 23348.672] (assumes normal distribution)
# JMH 1.11.2 (released 1512 days ago, please consider updating!)
# VM version: JDK 1.8.0_231, VM 25.231-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: 7 iterations, 1 s each
# Measurement: 10 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.mitchellbosecke.benchmark.Mustache.benchmark
# Run progress: 40.00% complete, ETA 00:01:45
# Fork: 1 of 1
# Warmup Iteration 1: 17535.313 ops/s
# Warmup Iteration 2: 23993.906 ops/s
# Warmup Iteration 3: 23758.839 ops/s
# Warmup Iteration 4: 24852.563 ops/s
# Warmup Iteration 5: 26130.397 ops/s
# Warmup Iteration 6: 25813.815 ops/s
# Warmup Iteration 7: 25822.804 ops/s
Iteration 1: 25829.128 ops/s
Iteration 2: 25648.836 ops/s
Iteration 3: 25852.150 ops/s
Iteration 4: 26042.862 ops/s
Iteration 5: 26025.606 ops/s
Iteration 6: 25801.628 ops/s
Iteration 7: 25815.660 ops/s
Iteration 8: 25960.610 ops/s
Iteration 9: 25827.831 ops/s
Iteration 10: 26194.905 ops/s
Result "benchmark":
25899.922 ±(99.9%) 235.957 ops/s [Average]
(min, avg, max) = (25648.836, 25899.922, 26194.905), stdev = 156.071
CI (99.9%): [25663.965, 26135.879] (assumes normal distribution)
# JMH 1.11.2 (released 1512 days ago, please consider updating!)
# VM version: JDK 1.8.0_231, VM 25.231-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: 7 iterations, 1 s each
# Measurement: 10 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.mitchellbosecke.benchmark.Pebble.benchmark
# Run progress: 50.00% complete, ETA 00:01:27
# Fork: 1 of 1
# Warmup Iteration 1: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
27168.276 ops/s
# Warmup Iteration 2: 32613.551 ops/s
# Warmup Iteration 3: 38244.156 ops/s
# Warmup Iteration 4: 39785.774 ops/s
# Warmup Iteration 5: 44299.959 ops/s
# Warmup Iteration 6: 44434.804 ops/s
# Warmup Iteration 7: 44571.050 ops/s
Iteration 1: 44247.614 ops/s
Iteration 2: 44247.773 ops/s
Iteration 3: 43517.520 ops/s
Iteration 4: 43722.531 ops/s
Iteration 5: 43991.663 ops/s
Iteration 6: 44506.856 ops/s
Iteration 7: 44459.715 ops/s
Iteration 8: 40458.385 ops/s
Iteration 9: 44028.232 ops/s
Iteration 10: 44382.664 ops/s
Result "benchmark":
43756.295 ±(99.9%) 1816.826 ops/s [Average]
(min, avg, max) = (40458.385, 43756.295, 44506.856), stdev = 1201.718
CI (99.9%): [41939.469, 45573.121] (assumes normal distribution)
# JMH 1.11.2 (released 1512 days ago, please consider updating!)
# VM version: JDK 1.8.0_231, VM 25.231-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: 7 iterations, 1 s each
# Measurement: 10 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.mitchellbosecke.benchmark.Rocker.benchmark
# Run progress: 60.00% complete, ETA 00:01:10
# Fork: 1 of 1
# Warmup Iteration 1: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
33854.778 ops/s
# Warmup Iteration 2: 42459.314 ops/s
# Warmup Iteration 3: 48707.841 ops/s
# Warmup Iteration 4: 49277.922 ops/s
# Warmup Iteration 5: 49129.981 ops/s
# Warmup Iteration 6: 49509.122 ops/s
# Warmup Iteration 7: 49198.592 ops/s
Iteration 1: 49195.148 ops/s
Iteration 2: 49632.069 ops/s
Iteration 3: 48999.080 ops/s
Iteration 4: 49195.088 ops/s
Iteration 5: 49243.290 ops/s
Iteration 6: 47891.038 ops/s
Iteration 7: 49088.378 ops/s
Iteration 8: 49020.226 ops/s
Iteration 9: 49279.872 ops/s
Iteration 10: 49351.368 ops/s
Result "benchmark":
49089.556 ±(99.9%) 693.635 ops/s [Average]
(min, avg, max) = (47891.038, 49089.556, 49632.069), stdev = 458.796
CI (99.9%): [48395.921, 49783.190] (assumes normal distribution)
# JMH 1.11.2 (released 1512 days ago, please consider updating!)
# VM version: JDK 1.8.0_231, VM 25.231-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: 7 iterations, 1 s each
# Measurement: 10 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.mitchellbosecke.benchmark.Thymeleaf.benchmark
# Run progress: 70.00% complete, ETA 00:00:52
# Fork: 1 of 1
# Warmup Iteration 1: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2057.178 ops/s
# Warmup Iteration 2: 5408.899 ops/s
# Warmup Iteration 3: 5059.918 ops/s
# Warmup Iteration 4: 6139.924 ops/s
# Warmup Iteration 5: 7035.402 ops/s
# Warmup Iteration 6: 7094.740 ops/s
# Warmup Iteration 7: 7084.667 ops/s
Iteration 1: 7018.652 ops/s
Iteration 2: 7001.913 ops/s
Iteration 3: 6795.352 ops/s
Iteration 4: 7080.256 ops/s
Iteration 5: 7101.143 ops/s
Iteration 6: 6964.797 ops/s
Iteration 7: 7076.073 ops/s
Iteration 8: 7052.836 ops/s
Iteration 9: 7064.871 ops/s
Iteration 10: 6831.275 ops/s
Result "benchmark":
6998.717 ±(99.9%) 160.461 ops/s [Average]
(min, avg, max) = (6795.352, 6998.717, 7101.143), stdev = 106.135
CI (99.9%): [6838.256, 7159.177] (assumes normal distribution)
# JMH 1.11.2 (released 1512 days ago, please consider updating!)
# VM version: JDK 1.8.0_231, VM 25.231-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: 7 iterations, 1 s each
# Measurement: 10 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.mitchellbosecke.benchmark.Trimou.benchmark
# Run progress: 80.00% complete, ETA 00:00:34
# Fork: 1 of 1
# Warmup Iteration 1: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
20176.562 ops/s
# Warmup Iteration 2: 25219.391 ops/s
# Warmup Iteration 3: 28882.489 ops/s
# Warmup Iteration 4: 28674.271 ops/s
# Warmup Iteration 5: 28947.661 ops/s
# Warmup Iteration 6: 28699.878 ops/s
# Warmup Iteration 7: 29350.914 ops/s
Iteration 1: 29148.581 ops/s
Iteration 2: 28822.351 ops/s
Iteration 3: 28565.120 ops/s
Iteration 4: 27519.283 ops/s
Iteration 5: 28694.823 ops/s
Iteration 6: 28006.620 ops/s
Iteration 7: 28561.401 ops/s
Iteration 8: 28722.204 ops/s
Iteration 9: 28389.563 ops/s
Iteration 10: 29189.294 ops/s
Result "benchmark":
28561.924 ±(99.9%) 759.969 ops/s [Average]
(min, avg, max) = (27519.283, 28561.924, 29189.294), stdev = 502.672
CI (99.9%): [27801.955, 29321.893] (assumes normal distribution)
# JMH 1.11.2 (released 1512 days ago, please consider updating!)
# VM version: JDK 1.8.0_231, VM 25.231-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: 7 iterations, 1 s each
# Measurement: 10 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.mitchellbosecke.benchmark.Velocity.benchmark
# Run progress: 90.00% complete, ETA 00:00:17
# Fork: 1 of 1
# Warmup Iteration 1: 17798.011 ops/s
# Warmup Iteration 2: 19231.510 ops/s
# Warmup Iteration 3: 21294.027 ops/s
# Warmup Iteration 4: 22293.956 ops/s
# Warmup Iteration 5: 24805.921 ops/s
# Warmup Iteration 6: 24786.870 ops/s
# Warmup Iteration 7: 25496.960 ops/s
Iteration 1: 25338.231 ops/s
Iteration 2: 25153.088 ops/s
Iteration 3: 25256.198 ops/s
Iteration 4: 25246.344 ops/s
Iteration 5: 25063.117 ops/s
Iteration 6: 24941.525 ops/s
Iteration 7: 24951.636 ops/s
Iteration 8: 25156.106 ops/s
Iteration 9: 24865.445 ops/s
Iteration 10: 24902.477 ops/s
Result "benchmark":
25087.417 ±(99.9%) 251.709 ops/s [Average]
(min, avg, max) = (24865.445, 25087.417, 25338.231), stdev = 166.490
CI (99.9%): [24835.708, 25339.125] (assumes normal distribution)
# Run complete. Total time: 00:02:55
Benchmark Mode Cnt Score Error Units
Beetl.benchmark thrpt 10 80685.217 ± 3056.314 ops/s
Enjoy.benchmark thrpt 10 71429.555 ± 626.639 ops/s
Freemarker.benchmark thrpt 10 22262.620 ± 917.084 ops/s
Handlebars.benchmark thrpt 10 23077.234 ± 271.438 ops/s
Mustache.benchmark thrpt 10 25899.922 ± 235.957 ops/s
Pebble.benchmark thrpt 10 43756.295 ± 1816.826 ops/s
Rocker.benchmark thrpt 10 49089.556 ± 693.635 ops/s
Thymeleaf.benchmark thrpt 10 6998.717 ± 160.461 ops/s
Trimou.benchmark thrpt 10 28561.924 ± 759.969 ops/s
Velocity.benchmark thrpt 10 25087.417 ± 251.709 ops/s