* Update dependencies for benchmarks Template engines - maud 0.17.1 (local) - handlebars 0.29.1 - horrorshow 0.6.2 - liquid 0.10.1 - tera 0.10.10 * Update benchmark dependencies * Remove unused feature * Revert indentation * Fix unused Result
50 lines
1.1 KiB
Rust
50 lines
1.1 KiB
Rust
#![feature(proc_macro, test)]
|
|
|
|
#[macro_use]
|
|
extern crate serde_derive;
|
|
extern crate tera;
|
|
extern crate test;
|
|
|
|
use tera::{Context, Tera};
|
|
|
|
#[derive(Serialize, Debug)]
|
|
struct Entry {
|
|
name: &'static str,
|
|
score: u16,
|
|
}
|
|
|
|
static SOURCE: &'static str = "<html>
|
|
<head>
|
|
<title>{{ year }}</title>
|
|
</head>
|
|
<body>
|
|
<h1>CSL {{ year }}</h1>
|
|
<ul>
|
|
{% for team in teams %}
|
|
<li class=\"{% if loop.first %}champion{% endif %}\">
|
|
<b>{{ team.name }}</b>: {{ team.score }}
|
|
</li>
|
|
{% endfor %}
|
|
</ul>
|
|
</body>
|
|
</html>";
|
|
|
|
#[bench]
|
|
fn render_template(b: &mut test::Bencher) {
|
|
let mut tera = test::black_box(Tera::default());
|
|
tera.add_raw_template("table", SOURCE).unwrap();
|
|
|
|
let context = test::black_box({
|
|
let mut context = Context::new();
|
|
context.add("teams", &[
|
|
Entry { name: "Jiangsu", score: 43 },
|
|
Entry { name: "Beijing", score: 27 },
|
|
Entry { name: "Guangzhou", score: 22 },
|
|
Entry { name: "Shandong", score: 12 },
|
|
]);
|
|
context.add("year", &"2015");
|
|
context
|
|
});
|
|
|
|
b.iter(|| tera.render("table", &context));
|
|
}
|