use std::io::Write;
use v_htmlescape::escape;
use criterion;
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);
}
b.iter(|| {
let mut output = Vec::new();
write!(&mut output, "
").unwrap();
for r1 in &table {
write!(&mut output, "\n").unwrap();
for r2 in r1 {
write!(&mut output, "{col} | ", col = r2).unwrap();
}
write!(&mut output, "
\n").unwrap();
}
write!(&mut output, "
").unwrap();
output
});
}
pub fn teams(b: &mut criterion::Bencher<'_>, _: &usize) {
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(|| {
let mut output = Vec::new();
write!(
&mut output,
"
{year}
CSL {year}
",
year = teams.year
)
.unwrap();
for (i, team) in (&teams).teams.iter().enumerate() {
let champion = if i != 0 { "" } else { "champion" };
write!(
&mut output,
"-
{name}: {score}",
champion = escape(champion),
name = escape(&team.name),
score = team.score
)
.unwrap();
}
write!(
&mut output,
"
"
)
.unwrap();
output
});
}
struct Teams {
year: u16,
teams: Vec,
}
struct Team {
name: String,
score: u8,
}