|
1 |
| -package levsha.benchmark |
2 |
| - |
3 |
| -import org.openjdk.jmh.annotations.{Benchmark, Param, Scope, State} |
4 |
| -import levsha.dsl.SymbolDsl |
5 |
| - |
6 |
| -@State(Scope.Benchmark) |
7 |
| -class StaticRenderingComparision { |
8 |
| - |
9 |
| - import StaticRenderingComparision.engines |
10 |
| - |
11 |
| - // TODO "beard" |
12 |
| - @Param(Array("levsha", "scalatags", "twirl")) |
13 |
| - var engineName: String = _ |
14 |
| - |
15 |
| - @Benchmark def simpleHtml(): Unit = engines(engineName).simpleHtml() |
16 |
| - @Benchmark def withVariables(): Unit = engines(engineName).withVariables() |
17 |
| - @Benchmark def withConditionAndLoop(): Unit = engines(engineName).withConditionAndLoop() |
18 |
| -} |
19 |
| - |
20 |
| -object StaticRenderingComparision { |
21 |
| - |
22 |
| - trait TemplateEngine { |
23 |
| - def simpleHtml(): Unit |
24 |
| - def withVariables(): Unit |
25 |
| - def withConditionAndLoop(): Unit |
26 |
| - } |
27 |
| - |
28 |
| - val engines = Map( |
29 |
| - |
30 |
| - "levsha" -> new TemplateEngine { |
31 |
| - |
32 |
| - val symbolDsl = new SymbolDsl[Nothing]() |
33 |
| - |
34 |
| - import sharedContent._ |
35 |
| - import levsha.text.renderHtml |
36 |
| - import symbolDsl._ |
37 |
| - |
38 |
| - def simpleHtml(): Unit = { |
39 |
| - renderHtml { |
40 |
| - 'body( |
41 |
| - 'div('class /= "title", "Hello, I'm Cow!"), |
42 |
| - 'ul('class /= "list", |
43 |
| - 'li("One"), |
44 |
| - 'li("Two"), |
45 |
| - 'li("Three"), |
46 |
| - 'li("..."), |
47 |
| - 'li("Moooo") |
48 |
| - ) |
49 |
| - ) |
50 |
| - } |
51 |
| - } |
52 |
| - def withVariables(): Unit = { |
53 |
| - renderHtml { |
54 |
| - 'body( |
55 |
| - 'div('class /= "title", greeting), |
56 |
| - 'ul('class /= className, |
57 |
| - 'li("One"), |
58 |
| - 'li("Two"), |
59 |
| - 'li("Three"), |
60 |
| - 'li("..."), |
61 |
| - 'li("Moooo") |
62 |
| - ) |
63 |
| - ) |
64 |
| - } |
65 |
| - } |
66 |
| - def withConditionAndLoop(): Unit = { |
67 |
| - renderHtml { |
68 |
| - 'body( |
69 |
| - 'div('class /= "title", |
70 |
| - if (condition) leftBranch |
71 |
| - else rightBranch |
72 |
| - ), |
73 |
| - 'ul('class /= className, |
74 |
| - items.map(item => 'li(item)) |
75 |
| - ) |
76 |
| - ) |
77 |
| - } |
78 |
| - } |
79 |
| - }, |
80 |
| - |
81 |
| - "scalatags" -> new TemplateEngine { |
82 |
| - |
83 |
| - import sharedContent._ |
84 |
| - import scalatags.Text.all._ |
85 |
| - |
86 |
| - def simpleHtml(): Unit = { |
87 |
| - val tags = body( |
88 |
| - div(`class` := "title")("Hello, I'm Cow!"), |
89 |
| - ul(`class` := "list")( |
90 |
| - li("One"), |
91 |
| - li("Two"), |
92 |
| - li("Three"), |
93 |
| - li("..."), |
94 |
| - li("Moooo") |
95 |
| - ) |
96 |
| - ) |
97 |
| - tags.render |
98 |
| - } |
99 |
| - def withVariables(): Unit = { |
100 |
| - val tags = body( |
101 |
| - div(`class` := "title")(greeting), |
102 |
| - ul(`class` := className)( |
103 |
| - li("One"), |
104 |
| - li("Two"), |
105 |
| - li("Three"), |
106 |
| - li("..."), |
107 |
| - li("Moooo") |
108 |
| - ) |
109 |
| - ) |
110 |
| - tags.render |
111 |
| - } |
112 |
| - def withConditionAndLoop(): Unit = { |
113 |
| - val tags = body( |
114 |
| - div(`class` := "title")( |
115 |
| - if (condition) leftBranch |
116 |
| - else rightBranch |
117 |
| - ), |
118 |
| - ul(`class` := className)( |
119 |
| - items.map(item => li(item)) |
120 |
| - ) |
121 |
| - ) |
122 |
| - tags.render |
123 |
| - } |
124 |
| - }, |
125 |
| - |
126 |
| - "twirl" -> new TemplateEngine { |
127 |
| - import sharedContent._ |
128 |
| - def simpleHtml(): Unit = html.simple() |
129 |
| - def withVariables(): Unit = html.withVariables(greeting, className) |
130 |
| - def withConditionAndLoop(): Unit = html.withConditionAndLoop(condition, leftBranch, rightBranch, items) |
131 |
| - } |
132 |
| - ) |
133 |
| - |
134 |
| - // The content should be rendered by template engine |
135 |
| - object sharedContent { |
136 |
| - |
137 |
| - val greeting = "Hello, I'm Cow!" |
138 |
| - val className = "list" |
139 |
| - |
140 |
| - val condition = true |
141 |
| - val leftBranch = "Welcome!" |
142 |
| - val rightBranch = "Get off!" |
143 |
| - val items = Seq( |
144 |
| - "One", |
145 |
| - "Two", |
146 |
| - "Three", |
147 |
| - "...", |
148 |
| - "Moooo" |
149 |
| - ) |
150 |
| - } |
151 |
| -} |
| 1 | +//package levsha.benchmark |
| 2 | +// |
| 3 | +//import org.openjdk.jmh.annotations.{Benchmark, Param, Scope, State} |
| 4 | +//import levsha.dsl.SymbolDsl |
| 5 | +// |
| 6 | +//@State(Scope.Benchmark) |
| 7 | +//class StaticRenderingComparision { |
| 8 | +// |
| 9 | +// import StaticRenderingComparision.engines |
| 10 | +// |
| 11 | +// // TODO "beard" |
| 12 | +// @Param(Array("levsha", "scalatags", "twirl")) |
| 13 | +// var engineName: String = _ |
| 14 | +// |
| 15 | +// @Benchmark def simpleHtml(): Unit = engines(engineName).simpleHtml() |
| 16 | +// @Benchmark def withVariables(): Unit = engines(engineName).withVariables() |
| 17 | +// @Benchmark def withConditionAndLoop(): Unit = engines(engineName).withConditionAndLoop() |
| 18 | +//} |
| 19 | +// |
| 20 | +//object StaticRenderingComparision { |
| 21 | +// |
| 22 | +// trait TemplateEngine { |
| 23 | +// def simpleHtml(): Unit |
| 24 | +// def withVariables(): Unit |
| 25 | +// def withConditionAndLoop(): Unit |
| 26 | +// } |
| 27 | +// |
| 28 | +// val engines = Map( |
| 29 | +// |
| 30 | +// "levsha" -> new TemplateEngine { |
| 31 | +// |
| 32 | +// val symbolDsl = new SymbolDsl[Nothing]() |
| 33 | +// |
| 34 | +// import sharedContent._ |
| 35 | +// import levsha.text.renderHtml |
| 36 | +// import symbolDsl._ |
| 37 | +// |
| 38 | +// def simpleHtml(): Unit = { |
| 39 | +// renderHtml { |
| 40 | +// 'body( |
| 41 | +// 'div('class /= "title", "Hello, I'm Cow!"), |
| 42 | +// 'ul('class /= "list", |
| 43 | +// 'li("One"), |
| 44 | +// 'li("Two"), |
| 45 | +// 'li("Three"), |
| 46 | +// 'li("..."), |
| 47 | +// 'li("Moooo") |
| 48 | +// ) |
| 49 | +// ) |
| 50 | +// } |
| 51 | +// } |
| 52 | +// def withVariables(): Unit = { |
| 53 | +// renderHtml { |
| 54 | +// 'body( |
| 55 | +// 'div('class /= "title", greeting), |
| 56 | +// 'ul('class /= className, |
| 57 | +// 'li("One"), |
| 58 | +// 'li("Two"), |
| 59 | +// 'li("Three"), |
| 60 | +// 'li("..."), |
| 61 | +// 'li("Moooo") |
| 62 | +// ) |
| 63 | +// ) |
| 64 | +// } |
| 65 | +// } |
| 66 | +// def withConditionAndLoop(): Unit = { |
| 67 | +// renderHtml { |
| 68 | +// 'body( |
| 69 | +// 'div('class /= "title", |
| 70 | +// if (condition) leftBranch |
| 71 | +// else rightBranch |
| 72 | +// ), |
| 73 | +// 'ul('class /= className, |
| 74 | +// items.map(item => 'li(item)) |
| 75 | +// ) |
| 76 | +// ) |
| 77 | +// } |
| 78 | +// } |
| 79 | +// }, |
| 80 | +// |
| 81 | +// "scalatags" -> new TemplateEngine { |
| 82 | +// |
| 83 | +// import sharedContent._ |
| 84 | +// import scalatags.Text.all._ |
| 85 | +// |
| 86 | +// def simpleHtml(): Unit = { |
| 87 | +// val tags = body( |
| 88 | +// div(`class` := "title")("Hello, I'm Cow!"), |
| 89 | +// ul(`class` := "list")( |
| 90 | +// li("One"), |
| 91 | +// li("Two"), |
| 92 | +// li("Three"), |
| 93 | +// li("..."), |
| 94 | +// li("Moooo") |
| 95 | +// ) |
| 96 | +// ) |
| 97 | +// tags.render |
| 98 | +// } |
| 99 | +// def withVariables(): Unit = { |
| 100 | +// val tags = body( |
| 101 | +// div(`class` := "title")(greeting), |
| 102 | +// ul(`class` := className)( |
| 103 | +// li("One"), |
| 104 | +// li("Two"), |
| 105 | +// li("Three"), |
| 106 | +// li("..."), |
| 107 | +// li("Moooo") |
| 108 | +// ) |
| 109 | +// ) |
| 110 | +// tags.render |
| 111 | +// } |
| 112 | +// def withConditionAndLoop(): Unit = { |
| 113 | +// val tags = body( |
| 114 | +// div(`class` := "title")( |
| 115 | +// if (condition) leftBranch |
| 116 | +// else rightBranch |
| 117 | +// ), |
| 118 | +// ul(`class` := className)( |
| 119 | +// items.map(item => li(item)) |
| 120 | +// ) |
| 121 | +// ) |
| 122 | +// tags.render |
| 123 | +// } |
| 124 | +// }, |
| 125 | +// |
| 126 | +// "twirl" -> new TemplateEngine { |
| 127 | +// import sharedContent._ |
| 128 | +// def simpleHtml(): Unit = html.simple() |
| 129 | +// def withVariables(): Unit = html.withVariables(greeting, className) |
| 130 | +// def withConditionAndLoop(): Unit = html.withConditionAndLoop(condition, leftBranch, rightBranch, items) |
| 131 | +// } |
| 132 | +// ) |
| 133 | +// |
| 134 | +// // The content should be rendered by template engine |
| 135 | +// object sharedContent { |
| 136 | +// |
| 137 | +// val greeting = "Hello, I'm Cow!" |
| 138 | +// val className = "list" |
| 139 | +// |
| 140 | +// val condition = true |
| 141 | +// val leftBranch = "Welcome!" |
| 142 | +// val rightBranch = "Get off!" |
| 143 | +// val items = Seq( |
| 144 | +// "One", |
| 145 | +// "Two", |
| 146 | +// "Three", |
| 147 | +// "...", |
| 148 | +// "Moooo" |
| 149 | +// ) |
| 150 | +// } |
| 151 | +//} |
0 commit comments