-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} |