Skip to content

Commit

Permalink
Add spitfire-like benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
tailhook committed Nov 19, 2017
1 parent 012cefe commit 6494cb5
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions benches/spitfire.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! Benchmark from youtube/spitfire

#![feature(test)]

extern crate trimmer;
extern crate test;
#[macro_use] extern crate serde_json;

use trimmer::{Template, Context};
use serde_json::Value;
use test::Bencher;


fn template() -> Template {
trimmer::Parser::new().parse(r###"## syntax: indent
<table>
## for row in table
<tr>
## for _, column in row
<td>{{ column }}</td>
## endfor
</tr>
## endfor
</table>
"###).unwrap()
}

#[bench]
fn render(b: &mut Bencher) {
let tpl = template();
let row = json!({
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6,
"g": 7,
"h": 8,
"i": 9,
"j": 10,
});
let table = Value::Array((0..1000).map(|_| row.clone()).collect());
let mut ctx = Context::new();
ctx.set("table", &table);
b.iter(|| {
tpl.render(&ctx).unwrap();
});
}

0 comments on commit 6494cb5

Please sign in to comment.