Skip to content

Commit

Permalink
Parameterize macrobenchmarks, add throughput measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed Jul 12, 2022
1 parent d87eff8 commit f30a94f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 84 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
- [#393]: Added tests for reserved names (started with "xml"i) -- see <https://www.w3.org/TR/xml-names11/#xmlReserved>
- [#363]: Add tests for `Reader::read_event_impl` to ensure that proper events generated for corresponding inputs
- [#407]: Improved benchmark suite to cover whole-document parsing, escaping and unescaping text
- [#418]: Parameterized macrobenchmarks, added throughput measurements via criterion

[#8]: https://github.com/Mingun/fast-xml/pull/8
[#9]: https://github.com/Mingun/fast-xml/pull/9
Expand All @@ -137,6 +138,7 @@
[#407]: https://github.com/tafia/quick-xml/pull/407
[#412]: https://github.com/tafia/quick-xml/pull/412
[#416]: https://github.com/tafia/quick-xml/pull/416
[#418]: https://github.com/tafia/quick-xml/pull/418

## 0.23.0 -- 2022-05-08

Expand Down
118 changes: 34 additions & 84 deletions benches/macrobenches.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{self, criterion_group, Criterion};
use criterion::{self, criterion_group, Criterion, Throughput};
use quick_xml::events::Event;
use quick_xml::Reader;
use quick_xml::Result as XmlResult;
Expand Down Expand Up @@ -44,89 +44,39 @@ fn parse_document(doc: &[u8]) -> XmlResult<()> {
pub fn bench_fully_parse_document(c: &mut Criterion) {
let mut group = c.benchmark_group("fully_parse_document");

// long, mix of attributes and text, not much escaping, mix of attribute lengths, some namespaces
group.bench_function("rpm_primary.xml", |b| {
b.iter(|| {
parse_document(RPM_PRIMARY).unwrap();
})
});

// long, mix of attributes and text, not much escaping, mix of attribute lengths, some namespaces
group.bench_function("rpm_primary2.xml", |b| {
b.iter(|| {
parse_document(RPM_PRIMARY2).unwrap();
})
});

// long, mostly medium-length text elements, not much escaping
group.bench_function("rpm_filelists.xml", |b| {
b.iter(|| {
parse_document(RPM_FILELISTS).unwrap();
})
});

// long, mix of attributes and text, lots of escaping (both entity and char literal), long attributes
group.bench_function("rpm_other.xml", |b| {
b.iter(|| {
parse_document(RPM_OTHER).unwrap();
})
});

// long, mix of attributes and text, not much escaping, lots of non-ascii characters, lots of namespaces
group.bench_function("libreoffice_document.fodt", |b| {
b.iter(|| {
parse_document(LIBREOFFICE_DOCUMENT).unwrap();
})
});

// medium length, mostly empty tags, a few short attributes per element, no escaping
group.bench_function("document.xml", |b| {
b.iter(|| {
parse_document(DOCUMENT).unwrap();
})
});

// medium length, lots of namespaces, no escaping
group.bench_function("test_writer_ident.xml", |b| {
b.iter(|| {
parse_document(TEST_WRITER_INDENT).unwrap();
})
});

// short, mix of attributes and text, lots of escapes
group.bench_function("sample_1.xml", |b| {
b.iter(|| {
parse_document(SAMPLE_1).unwrap();
})
});

// medium length, lots of attributes, short attributes, few escapes
group.bench_function("linescore.xml", |b| {
b.iter(|| {
parse_document(LINESCORE).unwrap();
})
});

// short, lots of namespaces, no escapes
group.bench_function("sample_ns.xml", |b| {
b.iter(|| {
parse_document(SAMPLE_NS).unwrap();
})
});

// long, few attributes, mix of attribute lengths, escapes in text content
group.bench_function("sample_rss.xml", |b| {
b.iter(|| {
parse_document(SAMPLE_RSS).unwrap();
})
});

// long, lots of attributes, short attributes, no text, no escapes
group.bench_function("players.xml", |b| {
b.iter(|| {
parse_document(PLAYERS).unwrap();
})
});
let inputs = [
// long, mix of attributes and text, not much escaping, mix of attribute lengths, some namespaces
("rpm_primary.xml", RPM_PRIMARY),
// long, mix of attributes and text, not much escaping, mix of attribute lengths, some namespaces
("rpm_primary2.xml", RPM_PRIMARY2),
// long, mostly medium-length text elements, not much escaping
("rpm_filelists.xml", RPM_FILELISTS),
// long, mix of attributes and text, lots of escaping (both entity and char literal), long attributes
("rpm_other.xml", RPM_OTHER),
// long, mix of attributes and text, not much escaping, lots of non-ascii characters, lots of namespaces
("libreoffice_document.fodt", LIBREOFFICE_DOCUMENT),
// medium length, mostly empty tags, a few short attributes per element, no escaping
("document.xml", DOCUMENT),
// medium length, lots of namespaces, no escaping
("test_writer_ident.xml", TEST_WRITER_INDENT),
// short, mix of attributes and text, lots of escapes
("sample_1.xml", SAMPLE_1),
// medium length, lots of attributes, short attributes, few escapes
("linescore.xml", LINESCORE),
// short, lots of namespaces, no escapes
("sample_ns.xml", SAMPLE_NS),
// long, few attributes, mix of attribute lengths, escapes in text content
("sample_rss.xml", SAMPLE_RSS),
// long, lots of attributes, short attributes, no text, no escapes
("players.xml", PLAYERS),
];

for (id, data) in inputs.iter() {
group.throughput(Throughput::Bytes(data.len() as u64));
group.bench_with_input(*id, *data, |b, input| {
b.iter(|| parse_document(input).unwrap())
});
}

group.finish();
}
Expand Down

0 comments on commit f30a94f

Please sign in to comment.