use ::tera::{Context, Tera}; use criterion; use serde::Serialize; pub 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 mut tera = Tera::default(); tera.add_raw_templates(vec![("big-table.html", BIG_TABLE_TEMPLATE)]) .unwrap(); let mut ctx = Context::new(); ctx.insert("table", &table); let _ = tera.render("big-table.html", &ctx).unwrap(); b.iter(|| tera.render("big-table.html", &ctx)); } #[derive(Serialize)] struct Team { name: String, score: u8, } // Tera doesn't allow `escape` on number values static BIG_TABLE_TEMPLATE: &'static str = "
{{ col }} | {% endfor %}