在某个“新模板引擎”的基准测试增加Beetl,测试结果如下,可以看到Beetl还是很领先,每秒渲染80685次(我的机器是Mac Pro,Core I7)
1Benchmark Mode Cnt Score Error Units 2Beetl.benchmark thrpt 10 80685.217 ± 3056.314 ops/s 3Enjoy.benchmark thrpt 10 71429.555 ± 626.639 ops/s 4Freemarker.benchmark thrpt 10 22262.620 ± 917.084 ops/s 5Handlebars.benchmark thrpt 10 23077.234 ± 271.438 ops/s 6Mustache.benchmark thrpt 10 25899.922 ± 235.957 ops/s 7Pebble.benchmark thrpt 10 43756.295 ± 1816.826 ops/s 8Rocker.benchmark thrpt 10 49089.556 ± 693.635 ops/s 9Thymeleaf.benchmark thrpt 10 6998.717 ± 160.461 ops/s 10Trimou.benchmark thrpt 10 28561.924 ± 759.969 ops/s 11Velocity.benchmark thrpt 10 25087.417 ± 251.709 ops/s 12
最糟糕的依然是Thymeleaf,每秒渲染6998次。Beetl性能是它的12倍
Beetl很长时间没有在考虑性能优化方面的再升级了,这方面技术都是在大约5年前的技术,这些性能技术积累更来自于10年前,我还还写了一本书《Java系统性能优化实战》,把这些经验以及国外性能优秀工具的优化经验都通过代码说出来了
Beetl3升级主要方向还是朝着如何更方便用户使用和二次开发,比如不仅仅支持自定义定界符和占位符,还支持再定义一对。比如,支持很方便的重写语法树从而支持用户想要的特性等等。Beetl3已经朝着平台化发展,希望有人一想到模板设计模式,就能想到用Beetl完成。
如下是日志输出,如果你想读懂,你也可以购买我的书学习看看Java性能怎么玩
1>java -jar target/benchmarks.jar 2# JMH 1.11.2 (released 1512 days ago, please consider updating!) 3# VM version: JDK 1.8.0_231, VM 25.231-b11 4# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java 5# VM options: <none> 6# Warmup: 7 iterations, 1 s each 7# Measurement: 10 iterations, 1 s each 8# Timeout: 10 min per iteration 9# Threads: 1 thread, will synchronize iterations 10# Benchmark mode: Throughput, ops/time 11# Benchmark: com.mitchellbosecke.benchmark.Beetl.benchmark 12 13# Run progress: 0.00% complete, ETA 00:02:50 14# Fork: 1 of 1 15# Warmup Iteration 1: 51114.962 ops/s 16# Warmup Iteration 2: 68838.051 ops/s 17# Warmup Iteration 3: 80548.756 ops/s 18# Warmup Iteration 4: 80455.776 ops/s 19# Warmup Iteration 5: 82575.140 ops/s 20# Warmup Iteration 6: 81991.678 ops/s 21# Warmup Iteration 7: 81266.783 ops/s 22Iteration 1: 82013.802 ops/s 23Iteration 2: 82541.466 ops/s 24Iteration 3: 80045.919 ops/s 25Iteration 4: 79674.899 ops/s 26Iteration 5: 78000.984 ops/s 27Iteration 6: 76781.741 ops/s 28Iteration 7: 82078.755 ops/s 29Iteration 8: 81180.128 ops/s 30Iteration 9: 81764.501 ops/s 31Iteration 10: 82769.974 ops/s 32 33 34Result "benchmark": 35 80685.217 ±(99.9%) 3056.314 ops/s [Average] 36 (min, avg, max) = (76781.741, 80685.217, 82769.974), stdev = 2021.562 37 CI (99.9%): [77628.903, 83741.531] (assumes normal distribution) 38 39 40# JMH 1.11.2 (released 1512 days ago, please consider updating!) 41# VM version: JDK 1.8.0_231, VM 25.231-b11 42# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java 43# VM options: <none> 44# Warmup: 7 iterations, 1 s each 45# Measurement: 10 iterations, 1 s each 46# Timeout: 10 min per iteration 47# Threads: 1 thread, will synchronize iterations 48# Benchmark mode: Throughput, ops/time 49# Benchmark: com.mitchellbosecke.benchmark.Enjoy.benchmark 50 51# Run progress: 10.00% complete, ETA 00:02:37 52# Fork: 1 of 1 53# Warmup Iteration 1: 31215.408 ops/s 54# Warmup Iteration 2: 63274.067 ops/s 55# Warmup Iteration 3: 59576.189 ops/s 56# Warmup Iteration 4: 56251.571 ops/s 57# Warmup Iteration 5: 67626.645 ops/s 58# Warmup Iteration 6: 72074.793 ops/s 59# Warmup Iteration 7: 71176.183 ops/s 60Iteration 1: 70670.965 ops/s 61Iteration 2: 71391.061 ops/s 62Iteration 3: 71672.155 ops/s 63Iteration 4: 70904.271 ops/s 64Iteration 5: 71651.906 ops/s 65Iteration 6: 71427.132 ops/s 66Iteration 7: 71661.251 ops/s 67Iteration 8: 72070.550 ops/s 68Iteration 9: 71668.440 ops/s 69Iteration 10: 71177.815 ops/s 70 71 72Result "benchmark": 73 71429.555 ±(99.9%) 626.639 ops/s [Average] 74 (min, avg, max) = (70670.965, 71429.555, 72070.550), stdev = 414.483 75 CI (99.9%): [70802.916, 72056.193] (assumes normal distribution) 76 77 78# JMH 1.11.2 (released 1512 days ago, please consider updating!) 79# VM version: JDK 1.8.0_231, VM 25.231-b11 80# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java 81# VM options: <none> 82# Warmup: 7 iterations, 1 s each 83# Measurement: 10 iterations, 1 s each 84# Timeout: 10 min per iteration 85# Threads: 1 thread, will synchronize iterations 86# Benchmark mode: Throughput, ops/time 87# Benchmark: com.mitchellbosecke.benchmark.Freemarker.benchmark 88 89# Run progress: 20.00% complete, ETA 00:02:20 90# Fork: 1 of 1 91# Warmup Iteration 1: 12350.845 ops/s 92# Warmup Iteration 2: 15622.818 ops/s 93# Warmup Iteration 3: 15704.254 ops/s 94# Warmup Iteration 4: 17695.744 ops/s 95# Warmup Iteration 5: 23147.720 ops/s 96# Warmup Iteration 6: 22273.775 ops/s 97# Warmup Iteration 7: 21119.996 ops/s 98Iteration 1: 22007.723 ops/s 99Iteration 2: 23134.424 ops/s 100Iteration 3: 22243.061 ops/s 101Iteration 4: 22795.193 ops/s 102Iteration 5: 23060.673 ops/s 103Iteration 6: 22321.961 ops/s 104Iteration 7: 21464.161 ops/s 105Iteration 8: 22397.418 ops/s 106Iteration 9: 21724.151 ops/s 107Iteration 10: 21477.439 ops/s 108 109 110Result "benchmark": 111 22262.620 ±(99.9%) 917.084 ops/s [Average] 112 (min, avg, max) = (21464.161, 22262.620, 23134.424), stdev = 606.594 113 CI (99.9%): [21345.537, 23179.704] (assumes normal distribution) 114 115 116# JMH 1.11.2 (released 1512 days ago, please consider updating!) 117# VM version: JDK 1.8.0_231, VM 25.231-b11 118# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java 119# VM options: <none> 120# Warmup: 7 iterations, 1 s each 121# Measurement: 10 iterations, 1 s each 122# Timeout: 10 min per iteration 123# Threads: 1 thread, will synchronize iterations 124# Benchmark mode: Throughput, ops/time 125# Benchmark: com.mitchellbosecke.benchmark.Handlebars.benchmark 126 127# Run progress: 30.00% complete, ETA 00:02:02 128# Fork: 1 of 1 129# Warmup Iteration 1: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 130SLF4J: Defaulting to no-operation (NOP) logger implementation 131SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 132ANTLR 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 133# Warmup Iteration 2: 18012.201 ops/s 134# Warmup Iteration 3: 22485.044 ops/s 135# Warmup Iteration 4: 23362.141 ops/s 136# Warmup Iteration 5: 23085.279 ops/s 137# Warmup Iteration 6: 23253.656 ops/s 138# Warmup Iteration 7: 23129.963 ops/s 139Iteration 1: 23038.476 ops/s 140Iteration 2: 23235.933 ops/s 141Iteration 3: 23323.908 ops/s 142Iteration 4: 23188.352 ops/s 143Iteration 5: 22849.885 ops/s 144Iteration 6: 23006.736 ops/s 145Iteration 7: 22738.257 ops/s 146Iteration 8: 23144.517 ops/s 147Iteration 9: 23052.706 ops/s 148Iteration 10: 23193.571 ops/s 149 150 151Result "benchmark": 152 23077.234 ±(99.9%) 271.438 ops/s [Average] 153 (min, avg, max) = (22738.257, 23077.234, 23323.908), stdev = 179.539 154 CI (99.9%): [22805.797, 23348.672] (assumes normal distribution) 155 156 157# JMH 1.11.2 (released 1512 days ago, please consider updating!) 158# VM version: JDK 1.8.0_231, VM 25.231-b11 159# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java 160# VM options: <none> 161# Warmup: 7 iterations, 1 s each 162# Measurement: 10 iterations, 1 s each 163# Timeout: 10 min per iteration 164# Threads: 1 thread, will synchronize iterations 165# Benchmark mode: Throughput, ops/time 166# Benchmark: com.mitchellbosecke.benchmark.Mustache.benchmark 167 168# Run progress: 40.00% complete, ETA 00:01:45 169# Fork: 1 of 1 170# Warmup Iteration 1: 17535.313 ops/s 171# Warmup Iteration 2: 23993.906 ops/s 172# Warmup Iteration 3: 23758.839 ops/s 173# Warmup Iteration 4: 24852.563 ops/s 174# Warmup Iteration 5: 26130.397 ops/s 175# Warmup Iteration 6: 25813.815 ops/s 176# Warmup Iteration 7: 25822.804 ops/s 177Iteration 1: 25829.128 ops/s 178Iteration 2: 25648.836 ops/s 179Iteration 3: 25852.150 ops/s 180Iteration 4: 26042.862 ops/s 181Iteration 5: 26025.606 ops/s 182Iteration 6: 25801.628 ops/s 183Iteration 7: 25815.660 ops/s 184Iteration 8: 25960.610 ops/s 185Iteration 9: 25827.831 ops/s 186Iteration 10: 26194.905 ops/s 187 188 189Result "benchmark": 190 25899.922 ±(99.9%) 235.957 ops/s [Average] 191 (min, avg, max) = (25648.836, 25899.922, 26194.905), stdev = 156.071 192 CI (99.9%): [25663.965, 26135.879] (assumes normal distribution) 193 194 195# JMH 1.11.2 (released 1512 days ago, please consider updating!) 196# VM version: JDK 1.8.0_231, VM 25.231-b11 197# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java 198# VM options: <none> 199# Warmup: 7 iterations, 1 s each 200# Measurement: 10 iterations, 1 s each 201# Timeout: 10 min per iteration 202# Threads: 1 thread, will synchronize iterations 203# Benchmark mode: Throughput, ops/time 204# Benchmark: com.mitchellbosecke.benchmark.Pebble.benchmark 205 206# Run progress: 50.00% complete, ETA 00:01:27 207# Fork: 1 of 1 208# Warmup Iteration 1: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 209SLF4J: Defaulting to no-operation (NOP) logger implementation 210SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 21127168.276 ops/s 212# Warmup Iteration 2: 32613.551 ops/s 213# Warmup Iteration 3: 38244.156 ops/s 214# Warmup Iteration 4: 39785.774 ops/s 215# Warmup Iteration 5: 44299.959 ops/s 216# Warmup Iteration 6: 44434.804 ops/s 217# Warmup Iteration 7: 44571.050 ops/s 218Iteration 1: 44247.614 ops/s 219Iteration 2: 44247.773 ops/s 220Iteration 3: 43517.520 ops/s 221Iteration 4: 43722.531 ops/s 222Iteration 5: 43991.663 ops/s 223Iteration 6: 44506.856 ops/s 224Iteration 7: 44459.715 ops/s 225Iteration 8: 40458.385 ops/s 226Iteration 9: 44028.232 ops/s 227Iteration 10: 44382.664 ops/s 228 229 230Result "benchmark": 231 43756.295 ±(99.9%) 1816.826 ops/s [Average] 232 (min, avg, max) = (40458.385, 43756.295, 44506.856), stdev = 1201.718 233 CI (99.9%): [41939.469, 45573.121] (assumes normal distribution) 234 235 236# JMH 1.11.2 (released 1512 days ago, please consider updating!) 237# VM version: JDK 1.8.0_231, VM 25.231-b11 238# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java 239# VM options: <none> 240# Warmup: 7 iterations, 1 s each 241# Measurement: 10 iterations, 1 s each 242# Timeout: 10 min per iteration 243# Threads: 1 thread, will synchronize iterations 244# Benchmark mode: Throughput, ops/time 245# Benchmark: com.mitchellbosecke.benchmark.Rocker.benchmark 246 247# Run progress: 60.00% complete, ETA 00:01:10 248# Fork: 1 of 1 249# Warmup Iteration 1: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 250SLF4J: Defaulting to no-operation (NOP) logger implementation 251SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 25233854.778 ops/s 253# Warmup Iteration 2: 42459.314 ops/s 254# Warmup Iteration 3: 48707.841 ops/s 255# Warmup Iteration 4: 49277.922 ops/s 256# Warmup Iteration 5: 49129.981 ops/s 257# Warmup Iteration 6: 49509.122 ops/s 258# Warmup Iteration 7: 49198.592 ops/s 259Iteration 1: 49195.148 ops/s 260Iteration 2: 49632.069 ops/s 261Iteration 3: 48999.080 ops/s 262Iteration 4: 49195.088 ops/s 263Iteration 5: 49243.290 ops/s 264Iteration 6: 47891.038 ops/s 265Iteration 7: 49088.378 ops/s 266Iteration 8: 49020.226 ops/s 267Iteration 9: 49279.872 ops/s 268Iteration 10: 49351.368 ops/s 269 270 271Result "benchmark": 272 49089.556 ±(99.9%) 693.635 ops/s [Average] 273 (min, avg, max) = (47891.038, 49089.556, 49632.069), stdev = 458.796 274 CI (99.9%): [48395.921, 49783.190] (assumes normal distribution) 275 276 277# JMH 1.11.2 (released 1512 days ago, please consider updating!) 278# VM version: JDK 1.8.0_231, VM 25.231-b11 279# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java 280# VM options: <none> 281# Warmup: 7 iterations, 1 s each 282# Measurement: 10 iterations, 1 s each 283# Timeout: 10 min per iteration 284# Threads: 1 thread, will synchronize iterations 285# Benchmark mode: Throughput, ops/time 286# Benchmark: com.mitchellbosecke.benchmark.Thymeleaf.benchmark 287 288# Run progress: 70.00% complete, ETA 00:00:52 289# Fork: 1 of 1 290# Warmup Iteration 1: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 291SLF4J: Defaulting to no-operation (NOP) logger implementation 292SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 2932057.178 ops/s 294# Warmup Iteration 2: 5408.899 ops/s 295# Warmup Iteration 3: 5059.918 ops/s 296# Warmup Iteration 4: 6139.924 ops/s 297# Warmup Iteration 5: 7035.402 ops/s 298# Warmup Iteration 6: 7094.740 ops/s 299# Warmup Iteration 7: 7084.667 ops/s 300Iteration 1: 7018.652 ops/s 301Iteration 2: 7001.913 ops/s 302Iteration 3: 6795.352 ops/s 303Iteration 4: 7080.256 ops/s 304Iteration 5: 7101.143 ops/s 305Iteration 6: 6964.797 ops/s 306Iteration 7: 7076.073 ops/s 307Iteration 8: 7052.836 ops/s 308Iteration 9: 7064.871 ops/s 309Iteration 10: 6831.275 ops/s 310 311 312Result "benchmark": 313 6998.717 ±(99.9%) 160.461 ops/s [Average] 314 (min, avg, max) = (6795.352, 6998.717, 7101.143), stdev = 106.135 315 CI (99.9%): [6838.256, 7159.177] (assumes normal distribution) 316 317 318# JMH 1.11.2 (released 1512 days ago, please consider updating!) 319# VM version: JDK 1.8.0_231, VM 25.231-b11 320# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java 321# VM options: <none> 322# Warmup: 7 iterations, 1 s each 323# Measurement: 10 iterations, 1 s each 324# Timeout: 10 min per iteration 325# Threads: 1 thread, will synchronize iterations 326# Benchmark mode: Throughput, ops/time 327# Benchmark: com.mitchellbosecke.benchmark.Trimou.benchmark 328 329# Run progress: 80.00% complete, ETA 00:00:34 330# Fork: 1 of 1 331# Warmup Iteration 1: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 332SLF4J: Defaulting to no-operation (NOP) logger implementation 333SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 33420176.562 ops/s 335# Warmup Iteration 2: 25219.391 ops/s 336# Warmup Iteration 3: 28882.489 ops/s 337# Warmup Iteration 4: 28674.271 ops/s 338# Warmup Iteration 5: 28947.661 ops/s 339# Warmup Iteration 6: 28699.878 ops/s 340# Warmup Iteration 7: 29350.914 ops/s 341Iteration 1: 29148.581 ops/s 342Iteration 2: 28822.351 ops/s 343Iteration 3: 28565.120 ops/s 344Iteration 4: 27519.283 ops/s 345Iteration 5: 28694.823 ops/s 346Iteration 6: 28006.620 ops/s 347Iteration 7: 28561.401 ops/s 348Iteration 8: 28722.204 ops/s 349Iteration 9: 28389.563 ops/s 350Iteration 10: 29189.294 ops/s 351 352 353Result "benchmark": 354 28561.924 ±(99.9%) 759.969 ops/s [Average] 355 (min, avg, max) = (27519.283, 28561.924, 29189.294), stdev = 502.672 356 CI (99.9%): [27801.955, 29321.893] (assumes normal distribution) 357 358 359# JMH 1.11.2 (released 1512 days ago, please consider updating!) 360# VM version: JDK 1.8.0_231, VM 25.231-b11 361# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java 362# VM options: <none> 363# Warmup: 7 iterations, 1 s each 364# Measurement: 10 iterations, 1 s each 365# Timeout: 10 min per iteration 366# Threads: 1 thread, will synchronize iterations 367# Benchmark mode: Throughput, ops/time 368# Benchmark: com.mitchellbosecke.benchmark.Velocity.benchmark 369 370# Run progress: 90.00% complete, ETA 00:00:17 371# Fork: 1 of 1 372# Warmup Iteration 1: 17798.011 ops/s 373# Warmup Iteration 2: 19231.510 ops/s 374# Warmup Iteration 3: 21294.027 ops/s 375# Warmup Iteration 4: 22293.956 ops/s 376# Warmup Iteration 5: 24805.921 ops/s 377# Warmup Iteration 6: 24786.870 ops/s 378# Warmup Iteration 7: 25496.960 ops/s 379Iteration 1: 25338.231 ops/s 380Iteration 2: 25153.088 ops/s 381Iteration 3: 25256.198 ops/s 382Iteration 4: 25246.344 ops/s 383Iteration 5: 25063.117 ops/s 384Iteration 6: 24941.525 ops/s 385Iteration 7: 24951.636 ops/s 386Iteration 8: 25156.106 ops/s 387Iteration 9: 24865.445 ops/s 388Iteration 10: 24902.477 ops/s 389 390 391Result "benchmark": 392 25087.417 ±(99.9%) 251.709 ops/s [Average] 393 (min, avg, max) = (24865.445, 25087.417, 25338.231), stdev = 166.490 394 CI (99.9%): [24835.708, 25339.125] (assumes normal distribution) 395 396 397# Run complete. Total time: 00:02:55 398 399Benchmark Mode Cnt Score Error Units 400Beetl.benchmark thrpt 10 80685.217 ± 3056.314 ops/s 401Enjoy.benchmark thrpt 10 71429.555 ± 626.639 ops/s 402Freemarker.benchmark thrpt 10 22262.620 ± 917.084 ops/s 403Handlebars.benchmark thrpt 10 23077.234 ± 271.438 ops/s 404Mustache.benchmark thrpt 10 25899.922 ± 235.957 ops/s 405Pebble.benchmark thrpt 10 43756.295 ± 1816.826 ops/s 406Rocker.benchmark thrpt 10 49089.556 ± 693.635 ops/s 407Thymeleaf.benchmark thrpt 10 6998.717 ± 160.461 ops/s 408Trimou.benchmark thrpt 10 28561.924 ± 759.969 ops/s 409Velocity.benchmark thrpt 10 25087.417 ± 251.709 ops/s