maud/benchmarks/benches/horrorshow.rs

60 lines
1.3 KiB
Rust
Raw Normal View History

2016-10-02 17:24:36 +13:00
#![feature(test)]
extern crate test;
2019-03-17 19:35:06 +13:00
use horrorshow::html;
2016-10-02 17:24:36 +13:00
use horrorshow::prelude::*;
#[derive(Debug)]
struct Entry {
name: &'static str,
score: u16,
}
#[bench]
fn render_template(b: &mut test::Bencher) {
let year = test::black_box("2015");
let teams = test::black_box(vec![
2020-09-27 21:36:27 +10:00
Entry {
name: "Jiangsu",
score: 43,
},
Entry {
name: "Beijing",
score: 27,
},
Entry {
name: "Guangzhou",
score: 22,
},
Entry {
name: "Shandong",
score: 12,
},
2016-10-02 17:24:36 +13:00
]);
b.iter(|| {
(html! {
html {
head {
title : year;
}
body {
h1 { : "CSL "; : year }
ul {
@ for (i, team) in teams.iter().enumerate() {
li(class=(if i == 0 { "champion" } else { "" })) {
b : (team.name);
: ": ";
: (team.score);
}
}
}
}
}
2020-09-27 21:36:27 +10:00
})
.into_string()
.unwrap()
2016-10-02 17:24:36 +13:00
});
}