|
3 | 3 | import com.github.mustachejava.DefaultMustacheFactory; |
4 | 4 | import com.github.mustachejava.Mustache; |
5 | 5 | import com.github.mustachejava.reflect.SimpleObjectHandler; |
| 6 | +import com.github.mustachejava.util.HtmlEscaper; |
6 | 7 | import com.github.mustachejavabenchmarks.NullWriter; |
7 | | -import org.openjdk.jmh.annotations.Scope; |
8 | | -import org.openjdk.jmh.annotations.State; |
| 8 | +import org.openjdk.jmh.annotations.*; |
9 | 9 |
|
10 | 10 | import java.io.IOException; |
11 | 11 | import java.io.StringReader; |
12 | 12 | import java.util.ArrayList; |
13 | 13 | import java.util.List; |
| 14 | +import java.util.concurrent.TimeUnit; |
14 | 15 |
|
15 | 16 | /* |
16 | 17 |
|
|
37 | 38 | Main.benchJustEscapeOnce thrpt 20 102768645.605 ± 3764598.754 ops/s |
38 | 39 | Main.benchJustEscapeTwo thrpt 20 81450001.026 ± 2270993.769 ops/s |
39 | 40 |
|
| 41 | +Now purely an array lookup |
| 42 | +Benchmark Mode Cnt Score Error Units |
| 43 | +Main.benchJustEscapeClean thrpt 20 408133726.531 ± 41452124.506 ops/s |
| 44 | +Main.benchJustEscapeOldClean thrpt 20 136543848.645 ± 4981651.587 ops/s |
| 45 | +Main.benchJustEscapeOnce thrpt 20 216812988.639 ± 16074660.164 ops/s |
| 46 | +Main.benchJustEscapeTwo thrpt 20 101607565.357 ± 5789918.319 ops/s |
| 47 | +
|
40 | 48 | Benchmark Mode Cnt Score Error Units |
41 | 49 | Main.benchMustache thrpt 20 763256.970 ± 59474.781 ops/s |
42 | 50 |
|
@@ -79,45 +87,39 @@ public class Main { |
79 | 87 | } |
80 | 88 | } |
81 | 89 |
|
82 | | -// @Benchmark |
83 | | -// @BenchmarkMode(Mode.Throughput) |
84 | | -// @OutputTimeUnit(TimeUnit.SECONDS) |
85 | | -// public void benchMustache() throws IOException { |
86 | | -// normal.execute(nw, scope).close(); |
87 | | -// } |
88 | | -// |
89 | | -// @Benchmark |
90 | | -// @BenchmarkMode(Mode.Throughput) |
91 | | -// @OutputTimeUnit(TimeUnit.SECONDS) |
92 | | -// public void benchMustacheSimple() throws IOException { |
93 | | -// simple.execute(nw, scope).close(); |
94 | | -// } |
95 | | - |
96 | | - |
97 | | -// @Benchmark |
98 | | -// public void benchTheoreticalLimit() throws IOException { |
99 | | -// nw.write("variable"); |
100 | | -// } |
101 | | -// |
102 | | -// @Benchmark |
103 | | -// public void benchJustEscapeClean() { |
104 | | -// HtmlEscaper.escape("variable", nw); |
105 | | -// } |
106 | | -// |
107 | | -// @Benchmark |
108 | | -// public void benchJustEscapeOnce() { |
109 | | -// HtmlEscaper.escape("vari\"ble", nw); |
110 | | -// } |
111 | | -// |
112 | | -// @Benchmark |
113 | | -// public void benchJustEscapeTwo() { |
114 | | -// HtmlEscaper.escape("va&ri\"ble", nw); |
115 | | -// } |
| 90 | + @Benchmark |
| 91 | + @BenchmarkMode(Mode.Throughput) |
| 92 | + @OutputTimeUnit(TimeUnit.SECONDS) |
| 93 | + public void benchMustache() throws IOException { |
| 94 | + normal.execute(nw, scope).close(); |
| 95 | + } |
| 96 | + |
| 97 | + @Benchmark |
| 98 | + @BenchmarkMode(Mode.Throughput) |
| 99 | + @OutputTimeUnit(TimeUnit.SECONDS) |
| 100 | + public void benchMustacheSimple() throws IOException { |
| 101 | + simple.execute(nw, scope).close(); |
| 102 | + } |
| 103 | + |
| 104 | + @Benchmark |
| 105 | + public void benchJustEscapeClean() { |
| 106 | + HtmlEscaper.escape("variable", nw); |
| 107 | + } |
| 108 | + |
| 109 | + @Benchmark |
| 110 | + public void benchJustEscapeOnce() { |
| 111 | + HtmlEscaper.escape("vari\"ble", nw); |
| 112 | + } |
| 113 | + |
| 114 | + @Benchmark |
| 115 | + public void benchJustEscapeTwo() { |
| 116 | + HtmlEscaper.escape("va&ri\"ble", nw); |
| 117 | + } |
116 | 118 |
|
117 | 119 | public static void main(String[] args) throws IOException { |
118 | | -// Main main = new Main(); |
119 | | -// while (true) { |
120 | | -// main.benchMustacheSimple(); |
121 | | -// } |
| 120 | + Main main = new Main(); |
| 121 | + while (true) { |
| 122 | + main.benchMustacheSimple(); |
| 123 | + } |
122 | 124 | } |
123 | 125 | } |
0 commit comments