use criterion::{Criterion, black_box, criterion_group, criterion_main};
fn simple_email() -> &'static str {
r#"
Meeting Tomorrow
Hi Max,
Just confirming our meeting tomorrow at 2pm.
Please review the document beforehand.
Best,
Alice
"#
}
fn newsletter_email() -> &'static str {
r#"
Weekly Digest
Here are your updates:
- New feature: Dark mode is now available
- Bug fix: Resolved issue #123
- Update: API v2 documentation published
Thanks for reading!
Unsubscribe: click here
|
|
"#
}
fn reply_chain() -> &'static str {
r#"
On Tue, Jan 6, Bob wrote:
Here's the update you requested.
On Mon, Jan 5, Alice wrote:
What's the status on the deployment?
"#
}
fn large_email() -> String {
let paragraph = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. \
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.
";
let mut html = String::from("");
for i in 0..100 {
html.push_str(&format!("Section {}
", i));
html.push_str(paragraph);
}
html.push_str("");
html
}
fn bench_simple(c: &mut Criterion) {
let html = simple_email();
c.bench_function("simple_email", |b| {
b.iter(|| pter::convert(black_box(html)))
});
}
fn bench_newsletter(c: &mut Criterion) {
let html = newsletter_email();
c.bench_function("newsletter_layout_tables", |b| {
b.iter(|| pter::convert(black_box(html)))
});
}
fn bench_reply_chain(c: &mut Criterion) {
let html = reply_chain();
c.bench_function("reply_chain_nested", |b| {
b.iter(|| pter::convert(black_box(html)))
});
}
fn bench_large(c: &mut Criterion) {
let html = large_email();
c.bench_function("large_100_sections", |b| {
b.iter(|| pter::convert(black_box(&html)))
});
}
criterion_group!(benches, bench_simple, bench_newsletter, bench_reply_chain, bench_large);
criterion_main!(benches);