@@ -5,6 +5,7 @@ extern crate serde_derive;
5
5
6
6
use criterion:: Criterion ;
7
7
use handlebars:: { to_json, Context , Handlebars , Template } ;
8
+ use serde_json:: json;
8
9
use serde_json:: value:: Value as Json ;
9
10
use std:: collections:: BTreeMap ;
10
11
@@ -211,12 +212,65 @@ fn large_nested_loop(c: &mut Criterion) {
211
212
} ) ;
212
213
}
213
214
215
+ fn deeply_nested_partial ( c : & mut Criterion ) {
216
+ use std:: iter:: repeat;
217
+ let mut handlebars = Handlebars :: new ( ) ;
218
+
219
+ handlebars
220
+ . register_partial (
221
+ "nested_partial" ,
222
+ r#"{{#each baz}}
223
+ <div class="nested">
224
+ {{this}}{{#if (not @last)}}++{{/if}}
225
+ </div>
226
+ {{/each}}"# ,
227
+ )
228
+ . expect ( "Invalid template format" ) ;
229
+
230
+ handlebars
231
+ . register_partial (
232
+ "partial" ,
233
+ r#"
234
+ <div class="partial">
235
+ {{#each bar}}
236
+ {{>nested_partial}}
237
+ {{/each}}
238
+ </div>"# ,
239
+ )
240
+ . expect ( "Invalid template format" ) ;
241
+
242
+ handlebars
243
+ . register_template_string (
244
+ "test" ,
245
+ r#"
246
+ <div class="test">
247
+ {{#each foo}}
248
+ {{>partial}}
249
+ {{/each}}
250
+ </div>"# ,
251
+ )
252
+ . expect ( "Invalid template format" ) ;
253
+
254
+ let data = json ! ( {
255
+ "foo" : repeat( json!( {
256
+ "bar" : repeat( json!( {
257
+ "baz" : repeat( "xyz" ) . take( 7 ) . collect:: <Vec <_>>( )
258
+ } ) ) . take( 7 ) . collect:: <Vec <_>>( )
259
+ } ) ) . take( 7 ) . collect:: <Vec <_>>( )
260
+ } ) ;
261
+
262
+ let ctx = Context :: wraps ( data) . unwrap ( ) ;
263
+ c. bench_function ( "deeply_nested_partial" , move |b| {
264
+ b. iter ( || handlebars. render_with_context ( "test" , & ctx) . ok ( ) . unwrap ( ) ) ;
265
+ } ) ;
266
+ }
267
+
214
268
#[ cfg( unix) ]
215
269
criterion_group ! (
216
270
name = benches;
217
271
config = profiled( ) ;
218
272
targets = parse_template, render_template, large_loop_helper, large_loop_helper_with_context_creation,
219
- large_nested_loop
273
+ large_nested_loop, deeply_nested_partial
220
274
) ;
221
275
222
276
#[ cfg( not( unix) ) ]
@@ -226,7 +280,8 @@ criterion_group!(
226
280
render_template,
227
281
large_loop_helper,
228
282
large_loop_helper_with_context_creation,
229
- large_nested_loop
283
+ large_nested_loop,
284
+ deeply_nested_partial
230
285
) ;
231
286
232
287
criterion_main ! ( benches) ;
0 commit comments