8
8
static const std::string LongHtmlString = [] {
9
9
std::string S;
10
10
S.reserve (500000 );
11
- for (int i = 0 ; i < 50000 ; ++i ) {
11
+ for (int Idx = 0 ; Idx < 50000 ; ++Idx ) {
12
12
S += " <script>alert('xss');</script>" ;
13
13
}
14
14
return S;
@@ -153,7 +153,11 @@ static const std::string LargeOutputStringTemplate = "{{long_string}}";
153
153
// syntaxes.
154
154
static void BM_Mustache_StringRendering (benchmark::State &state,
155
155
const std::string &TplStr) {
156
- llvm::mustache::Template Tpl (TplStr);
156
+ llvm::BumpPtrAllocator Allocator;
157
+ llvm::StringSaver Saver (Allocator);
158
+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
159
+
160
+ llvm::mustache::Template Tpl (TplStr, Ctx);
157
161
llvm::json::Value Data =
158
162
llvm::json::Object ({{" content" , llvm::json::Value (LongHtmlString)}});
159
163
for (auto _ : state) {
@@ -172,7 +176,11 @@ BENCHMARK_CAPTURE(BM_Mustache_StringRendering, Unescaped_Ampersand,
172
176
// Tests the "hot render" cost of repeatedly traversing a deep and wide
173
177
// JSON object.
174
178
static void BM_Mustache_DeepTraversal (benchmark::State &state) {
175
- llvm::mustache::Template Tpl (DeepTraversalTemplate);
179
+ llvm::BumpPtrAllocator Allocator;
180
+ llvm::StringSaver Saver (Allocator);
181
+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
182
+
183
+ llvm::mustache::Template Tpl (DeepTraversalTemplate, Ctx);
176
184
for (auto _ : state) {
177
185
std::string Result;
178
186
llvm::raw_string_ostream OS (Result);
@@ -184,7 +192,12 @@ BENCHMARK(BM_Mustache_DeepTraversal);
184
192
185
193
// Tests the "hot render" cost of pushing and popping a deep context stack.
186
194
static void BM_Mustache_DeeplyNestedRendering (benchmark::State &state) {
187
- llvm::mustache::Template Tpl (DeeplyNestedRenderingTemplate);
195
+
196
+ llvm::BumpPtrAllocator Allocator;
197
+ llvm::StringSaver Saver (Allocator);
198
+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
199
+
200
+ llvm::mustache::Template Tpl (DeeplyNestedRenderingTemplate, Ctx);
188
201
for (auto _ : state) {
189
202
std::string Result;
190
203
llvm::raw_string_ostream OS (Result);
@@ -197,7 +210,11 @@ BENCHMARK(BM_Mustache_DeeplyNestedRendering);
197
210
// Tests the performance of the loop logic when iterating over a huge number of
198
211
// items.
199
212
static void BM_Mustache_HugeArrayIteration (benchmark::State &state) {
200
- llvm::mustache::Template Tpl (HugeArrayIterationTemplate);
213
+ llvm::BumpPtrAllocator Allocator;
214
+ llvm::StringSaver Saver (Allocator);
215
+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
216
+
217
+ llvm::mustache::Template Tpl (HugeArrayIterationTemplate, Ctx);
201
218
for (auto _ : state) {
202
219
std::string Result;
203
220
llvm::raw_string_ostream OS (Result);
@@ -209,25 +226,37 @@ BENCHMARK(BM_Mustache_HugeArrayIteration);
209
226
210
227
// Tests the performance of the parser on a large, "wide" template.
211
228
static void BM_Mustache_ComplexTemplateParsing (benchmark::State &state) {
229
+ llvm::BumpPtrAllocator Allocator;
230
+ llvm::StringSaver Saver (Allocator);
231
+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
232
+
212
233
for (auto _ : state) {
213
- llvm::mustache::Template Tpl (ComplexTemplateParsingTemplate);
234
+ llvm::mustache::Template Tpl (ComplexTemplateParsingTemplate, Ctx );
214
235
benchmark::DoNotOptimize (Tpl);
215
236
}
216
237
}
217
238
BENCHMARK (BM_Mustache_ComplexTemplateParsing);
218
239
219
240
// Tests the performance of the parser on a small, "deep" template.
220
241
static void BM_Mustache_SmallTemplateParsing (benchmark::State &state) {
242
+ llvm::BumpPtrAllocator Allocator;
243
+ llvm::StringSaver Saver (Allocator);
244
+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
245
+
221
246
for (auto _ : state) {
222
- llvm::mustache::Template Tpl (SmallTemplateParsingTemplate);
247
+ llvm::mustache::Template Tpl (SmallTemplateParsingTemplate, Ctx );
223
248
benchmark::DoNotOptimize (Tpl);
224
249
}
225
250
}
226
251
BENCHMARK (BM_Mustache_SmallTemplateParsing);
227
252
228
253
// Tests the performance of rendering a template that includes a partial.
229
254
static void BM_Mustache_PartialsRendering (benchmark::State &state) {
230
- llvm::mustache::Template Tpl (ComplexPartialTemplate);
255
+ llvm::BumpPtrAllocator Allocator;
256
+ llvm::StringSaver Saver (Allocator);
257
+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
258
+
259
+ llvm::mustache::Template Tpl (ComplexPartialTemplate, Ctx);
231
260
Tpl.registerPartial (" item_partial" , ItemPartialTemplate);
232
261
llvm::json::Value Data = HugeArrayData;
233
262
@@ -243,7 +272,11 @@ BENCHMARK(BM_Mustache_PartialsRendering);
243
272
// Tests the performance of the underlying buffer management when generating a
244
273
// very large output.
245
274
static void BM_Mustache_LargeOutputString (benchmark::State &state) {
246
- llvm::mustache::Template Tpl (LargeOutputStringTemplate);
275
+ llvm::BumpPtrAllocator Allocator;
276
+ llvm::StringSaver Saver (Allocator);
277
+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
278
+
279
+ llvm::mustache::Template Tpl (LargeOutputStringTemplate, Ctx);
247
280
for (auto _ : state) {
248
281
std::string Result;
249
282
llvm::raw_string_ostream OS (Result);
0 commit comments