Skip to content

Commit

Permalink
(test) added bench code for large each loop [#166]
Browse files Browse the repository at this point in the history
Signed-off-by: Ning Sun <sunng@about.me>
  • Loading branch information
sunng87 committed Jul 9, 2017
1 parent 6010f6a commit 57d1925
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
extern crate handlebars;
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate serde_derive;

extern crate test;

use std::collections::BTreeMap;
Expand Down Expand Up @@ -66,3 +69,23 @@ fn render_template(b: &mut test::Bencher) {
let data = make_data();
b.iter(|| handlebars.render("table", &data).ok().unwrap())
}

#[derive(Serialize)]
struct DataWrapper {
v: String,
}

#[bench]
fn large_loop_helper(b: &mut test::Bencher) {
let mut handlebars = Handlebars::new();
handlebars
.register_template_string("test", "BEFORE\n{{#each me}}{{this.v}}{{/each}}AFTER")
.ok()
.expect("Invalid template format");

let data: Vec<DataWrapper> = (1..10000)
.into_iter()
.map(|i| DataWrapper { v: format!("n={}", i) })
.collect();
b.iter(|| handlebars.render("test", &data).ok().unwrap());
}

0 comments on commit 57d1925

Please sign in to comment.