diff options
-rw-r--r-- | testing/Cargo.toml | 5 | ||||
-rw-r--r-- | testing/benches/all.rs | 59 | ||||
-rw-r--r-- | testing/templates/big-table.html | 5 | ||||
-rw-r--r-- | testing/templates/teams.html | 15 |
4 files changed, 84 insertions, 0 deletions
diff --git a/testing/Cargo.toml b/testing/Cargo.toml index 06fdf56..ff67e2e 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -10,6 +10,7 @@ nightly = ["rocket", "rocket_codegen", "askama/with-rocket"] [dependencies] askama = { path = "../askama", version = "*", features = ["with-iron", "serde-json"] } +criterion = "0.2" iron = "0.6" rocket = { version = "0.3", optional = true } rocket_codegen = { version = "0.3", optional = true } @@ -17,3 +18,7 @@ serde_json = "1.0" [build-dependencies] askama = { path = "../askama", version = "*", features = ["with-iron", "serde-json"] } + +[[bench]] +name = "all" +harness = false 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, +} diff --git a/testing/templates/big-table.html b/testing/templates/big-table.html new file mode 100644 index 0000000..2fbfce4 --- /dev/null +++ b/testing/templates/big-table.html @@ -0,0 +1,5 @@ +<table> +{% for row in table %} +<tr>{% for col in row %}<td>{{ col|escape }}</td>{% endfor %}</tr> +{% endfor %} +</table> diff --git a/testing/templates/teams.html b/testing/templates/teams.html new file mode 100644 index 0000000..cbeaec9 --- /dev/null +++ b/testing/templates/teams.html @@ -0,0 +1,15 @@ +<html> + <head> + <title>{{ year }}</title> + </head> + <body> + <h1>CSL {{ year }}</h1> + <ul> + {% for team in teams %} + <li class="{% if loop.index0 == 0 %}champion{% endif %}"> + <b>{{ team.name }}</b>: {{ team.score }} + </li> + {% endfor %} + </ul> + </body> +</html> |