mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 07:20:55 +00:00

We adopted `askama_escape` with the other askama crates. It was not updated for quite some time, but still gets 25k+ downloads / day Mon to Fri. This PR re-adds the crate using our current HTML escaping function.
27 lines
768 B
Rust
27 lines
768 B
Rust
use askama_escape::escape_html;
|
|
use criterion::{Criterion, Throughput, black_box, criterion_group, criterion_main};
|
|
|
|
criterion_main!(benches);
|
|
criterion_group!(benches, functions);
|
|
|
|
fn functions(c: &mut Criterion) {
|
|
c.bench_function("escape_html", escaping);
|
|
let mut g = c.benchmark_group("all");
|
|
let bytes = STRINGS.iter().map(|s| s.len() as u64).sum();
|
|
g.throughput(Throughput::Bytes(bytes));
|
|
g.bench_function("escape_html", escaping);
|
|
g.finish();
|
|
}
|
|
|
|
fn escaping(b: &mut criterion::Bencher<'_>) {
|
|
let mut dest = String::new();
|
|
b.iter(|| {
|
|
for &s in black_box(STRINGS) {
|
|
dest.clear();
|
|
black_box(escape_html(&mut dest, s)).unwrap();
|
|
}
|
|
});
|
|
}
|
|
|
|
const STRINGS: &[&str] = include!("strings.inc");
|