diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-06-28 17:01:12 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-06-28 17:01:12 +0200 |
commit | 970e3ecfbdf9e4e4c4faacdb87efa656e812398a (patch) | |
tree | 053c82e655441354004f4962d4d02e1674b7d8e4 /testing/benches/all.rs | |
parent | cb4fcbf379734345305065c2cce68046724a3408 (diff) | |
download | askama-970e3ecfbdf9e4e4c4faacdb87efa656e812398a.tar.gz askama-970e3ecfbdf9e4e4c4faacdb87efa656e812398a.tar.bz2 askama-970e3ecfbdf9e4e4c4faacdb87efa656e812398a.zip |
Add benchmarks to the Askama repo
Diffstat (limited to '')
-rw-r--r-- | testing/benches/all.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/testing/benches/all.rs b/testing/benches/all.rs new file mode 100644 index 0000000..862bd06 --- /dev/null +++ b/testing/benches/all.rs @@ -0,0 +1,59 @@ +#[macro_use] +extern crate askama; +#[macro_use] +extern crate criterion; + +use askama::Template; +use criterion::Criterion; + +criterion_main!(benches); +criterion_group!(benches, functions); + +fn functions(c: &mut Criterion) { + c.bench_function("Big table", |b| big_table(b, &100)); + c.bench_function("Teams", |b| teams(b)); +} + +fn big_table(b: &mut criterion::Bencher, size: &usize) { + let mut table = Vec::with_capacity(*size); + for _ in 0..*size { + let mut inner = Vec::with_capacity(*size); + for i in 0..*size { + inner.push(i); + } + table.push(inner); + } + let ctx = BigTable { table }; + b.iter(|| ctx.render().unwrap()); +} + +#[derive(Template)] +#[template(path = "big-table.html")] +struct BigTable { + table: Vec<Vec<usize>>, +} + +fn teams(b: &mut criterion::Bencher) { + let teams = Teams { + year: 2015, + teams: vec![ + Team { name: "Jiangsu".into(), score: 43 }, + Team { name: "Beijing".into(), score: 27 }, + Team { name: "Guangzhou".into(), score: 22 }, + Team { name: "Shandong".into(), score: 12 }, + ], + }; + b.iter(|| teams.render().unwrap()); +} + +#[derive(Template)] +#[template(path = "teams.html")] +struct Teams { + year: u16, + teams: Vec<Team>, +} + +struct Team { + name: String, + score: u8, +} |