Skip to content

Commit

Permalink
Break up benchmarks into sub-groups
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed Jan 5, 2022
1 parent d96c5c9 commit 8a74258
Showing 1 changed file with 51 additions and 28 deletions.
79 changes: 51 additions & 28 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ use criterion::{self, criterion_group, criterion_main, Criterion};
use quick_xml::events::Event;
use quick_xml::Reader;

fn quick_xml_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("metadata_parse");
static SAMPLE: &[u8] = include_bytes!("../tests/sample_rss.xml");
static PLAYERS: &[u8] = include_bytes!("../tests/players.xml");

let sample: &[u8] = include_bytes!("../tests/sample_rss.xml");
let players: &[u8] = include_bytes!("../tests/players.xml");

group.bench_function("quick_xml_normal", |b| {
fn quick_xml_normal(c: &mut Criterion) {
let mut group = c.benchmark_group("quick_xml_normal");
group.bench_function("untrimmed", |b| {
b.iter(|| {
let mut r = Reader::from_reader(sample);
let mut r = Reader::from_reader(SAMPLE);
r.check_end_names(false).check_comments(false);
let mut count = criterion::black_box(0);
let mut buf = Vec::new();
Expand All @@ -26,9 +25,9 @@ fn quick_xml_benchmark(c: &mut Criterion) {
})
});

group.bench_function("quick_xml_normal_trimmed", |b| {
group.bench_function("trimmed", |b| {
b.iter(|| {
let mut r = Reader::from_reader(sample);
let mut r = Reader::from_reader(SAMPLE);
r.check_end_names(false)
.check_comments(false)
.trim_text(true);
Expand All @@ -45,10 +44,14 @@ fn quick_xml_benchmark(c: &mut Criterion) {
assert_eq!(count, 1550);
});
});
group.finish();
}

group.bench_function("quick_xml_namespaced", |b| {
fn quick_xml_namespaced(c: &mut Criterion) {
let mut group = c.benchmark_group("quick_xml_namespaced");
group.bench_function("untrimmed", |b| {
b.iter(|| {
let mut r = Reader::from_reader(sample);
let mut r = Reader::from_reader(SAMPLE);
r.check_end_names(false).check_comments(false);
let mut count = criterion::black_box(0);
let mut buf = Vec::new();
Expand All @@ -65,9 +68,9 @@ fn quick_xml_benchmark(c: &mut Criterion) {
});
});

group.bench_function("quick_xml_namespaced_trimmed", |b| {
group.bench_function("trimmed", |b| {
b.iter(|| {
let mut r = Reader::from_reader(sample);
let mut r = Reader::from_reader(SAMPLE);
r.check_end_names(false)
.check_comments(false)
.trim_text(true);
Expand All @@ -85,11 +88,15 @@ fn quick_xml_benchmark(c: &mut Criterion) {
assert_eq!(count, 1550);
});
});
group.finish();
}

group.bench_function("quick_xml_escaped", |b| {
fn quick_xml_escaped(c: &mut Criterion) {
let mut group = c.benchmark_group("quick_xml_escaped");
group.bench_function("untrimmed", |b| {
b.iter(|| {
let mut buf = Vec::new();
let mut r = Reader::from_reader(sample);
let mut r = Reader::from_reader(SAMPLE);
r.check_end_names(false).check_comments(false);
let mut count = criterion::black_box(0);
let mut nbtxt = criterion::black_box(0);
Expand All @@ -113,10 +120,10 @@ fn quick_xml_benchmark(c: &mut Criterion) {
});
});

group.bench_function("quick_xml_escaped_trimmed", |b| {
group.bench_function("trimmed", |b| {
b.iter(|| {
let mut buf = Vec::new();
let mut r = Reader::from_reader(sample);
let mut r = Reader::from_reader(SAMPLE);
r.check_end_names(false)
.check_comments(false)
.trim_text(true);
Expand All @@ -141,8 +148,12 @@ fn quick_xml_benchmark(c: &mut Criterion) {
assert_eq!(nbtxt, 50261);
});
});
group.finish();
}

group.bench_function("quick_xml_one_text_event", |b| {
fn quick_xml_one_event(c: &mut Criterion) {
let mut group = c.benchmark_group("quick_xml_one_event");
group.bench_function("text_event", |b| {
let src = "Hello world!".repeat(512 / 12).into_bytes();
let mut buf = Vec::with_capacity(1024);
b.iter(|| {
Expand All @@ -160,7 +171,7 @@ fn quick_xml_benchmark(c: &mut Criterion) {
})
});

group.bench_function("quick_xml_one_start_event_trimmed", |b| {
group.bench_function("start_event_trimmed", |b| {
let src = format!(r#"<hello target="{}">"#, "world".repeat(512 / 5)).into_bytes();
let mut buf = Vec::with_capacity(1024);
b.iter(|| {
Expand All @@ -180,7 +191,7 @@ fn quick_xml_benchmark(c: &mut Criterion) {
})
});

group.bench_function("quick_xml_one_comment_event_trimmed", |b| {
group.bench_function("comment_event_trimmed", |b| {
let src = format!(r#"<!-- hello "{}" -->"#, "world".repeat(512 / 5)).into_bytes();
let mut buf = Vec::with_capacity(1024);
b.iter(|| {
Expand All @@ -200,7 +211,7 @@ fn quick_xml_benchmark(c: &mut Criterion) {
})
});

group.bench_function("quick_xml_one_cdata_event_trimmed", |b| {
group.bench_function("cdata_event_trimmed", |b| {
let src = format!(r#"<![CDATA[hello "{}"]]>"#, "world".repeat(512 / 5)).into_bytes();
let mut buf = Vec::with_capacity(1024);
b.iter(|| {
Expand All @@ -219,10 +230,14 @@ fn quick_xml_benchmark(c: &mut Criterion) {
assert_eq!(nbtxt, 518);
})
});
group.finish();
}

group.bench_function("quick_xml_iter_attributes", |b| {
fn quick_xml_attributes(c: &mut Criterion) {
let mut group = c.benchmark_group("quick_xml_attributes");
group.bench_function("iter_attributes", |b| {
b.iter(|| {
let mut r = Reader::from_reader(players);
let mut r = Reader::from_reader(PLAYERS);
r.check_end_names(false).check_comments(false);
let mut count = criterion::black_box(0);
let mut buf = Vec::new();
Expand All @@ -243,9 +258,9 @@ fn quick_xml_benchmark(c: &mut Criterion) {
})
});

group.bench_function("quick_xml_iter_attributes_no_checks", |b| {
group.bench_function("iter_attributes_no_checks", |b| {
b.iter(|| {
let mut r = Reader::from_reader(players);
let mut r = Reader::from_reader(PLAYERS);
r.check_end_names(false).check_comments(false);
let mut count = criterion::black_box(0);
let mut buf = Vec::new();
Expand All @@ -266,9 +281,9 @@ fn quick_xml_benchmark(c: &mut Criterion) {
})
});

group.bench_function("quick_xml_try_get_attribute", |b| {
group.bench_function("try_get_attribute", |b| {
b.iter(|| {
let mut r = Reader::from_reader(players);
let mut r = Reader::from_reader(PLAYERS);
r.check_end_names(false).check_comments(false);
let mut count = criterion::black_box(0);
let mut buf = Vec::new();
Expand All @@ -293,7 +308,15 @@ fn quick_xml_benchmark(c: &mut Criterion) {
assert_eq!(count, 150);
})
});
group.finish();
}

criterion_group!(benches, quick_xml_benchmark);
criterion_group!(
benches,
quick_xml_normal,
quick_xml_escaped,
quick_xml_namespaced,
quick_xml_one_event,
quick_xml_attributes
);
criterion_main!(benches);

0 comments on commit 8a74258

Please sign in to comment.