Skip to content

Commit a6588c2

Browse files
authored
Merge pull request #418 from dralley/benches
Parameterize benchmarks, add throughput measurements
2 parents d87eff8 + de51d9b commit a6588c2

File tree

3 files changed

+269
-263
lines changed

3 files changed

+269
-263
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
- [#393]: Added tests for reserved names (started with "xml"i) -- see <https://www.w3.org/TR/xml-names11/#xmlReserved>
122122
- [#363]: Add tests for `Reader::read_event_impl` to ensure that proper events generated for corresponding inputs
123123
- [#407]: Improved benchmark suite to cover whole-document parsing, escaping and unescaping text
124+
- [#418]: Parameterized macrobenchmarks and comparative benchmarks, added throughput measurements via criterion
124125

125126
[#8]: https://github.com/Mingun/fast-xml/pull/8
126127
[#9]: https://github.com/Mingun/fast-xml/pull/9
@@ -137,6 +138,7 @@
137138
[#407]: https://github.com/tafia/quick-xml/pull/407
138139
[#412]: https://github.com/tafia/quick-xml/pull/412
139140
[#416]: https://github.com/tafia/quick-xml/pull/416
141+
[#418]: https://github.com/tafia/quick-xml/pull/418
140142

141143
## 0.23.0 -- 2022-05-08
142144

benches/macrobenches.rs

Lines changed: 34 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use criterion::{self, criterion_group, Criterion};
1+
use criterion::{self, criterion_group, Criterion, Throughput};
22
use quick_xml::events::Event;
33
use quick_xml::Reader;
44
use quick_xml::Result as XmlResult;
@@ -44,89 +44,39 @@ fn parse_document(doc: &[u8]) -> XmlResult<()> {
4444
pub fn bench_fully_parse_document(c: &mut Criterion) {
4545
let mut group = c.benchmark_group("fully_parse_document");
4646

47-
// long, mix of attributes and text, not much escaping, mix of attribute lengths, some namespaces
48-
group.bench_function("rpm_primary.xml", |b| {
49-
b.iter(|| {
50-
parse_document(RPM_PRIMARY).unwrap();
51-
})
52-
});
53-
54-
// long, mix of attributes and text, not much escaping, mix of attribute lengths, some namespaces
55-
group.bench_function("rpm_primary2.xml", |b| {
56-
b.iter(|| {
57-
parse_document(RPM_PRIMARY2).unwrap();
58-
})
59-
});
60-
61-
// long, mostly medium-length text elements, not much escaping
62-
group.bench_function("rpm_filelists.xml", |b| {
63-
b.iter(|| {
64-
parse_document(RPM_FILELISTS).unwrap();
65-
})
66-
});
67-
68-
// long, mix of attributes and text, lots of escaping (both entity and char literal), long attributes
69-
group.bench_function("rpm_other.xml", |b| {
70-
b.iter(|| {
71-
parse_document(RPM_OTHER).unwrap();
72-
})
73-
});
74-
75-
// long, mix of attributes and text, not much escaping, lots of non-ascii characters, lots of namespaces
76-
group.bench_function("libreoffice_document.fodt", |b| {
77-
b.iter(|| {
78-
parse_document(LIBREOFFICE_DOCUMENT).unwrap();
79-
})
80-
});
81-
82-
// medium length, mostly empty tags, a few short attributes per element, no escaping
83-
group.bench_function("document.xml", |b| {
84-
b.iter(|| {
85-
parse_document(DOCUMENT).unwrap();
86-
})
87-
});
88-
89-
// medium length, lots of namespaces, no escaping
90-
group.bench_function("test_writer_ident.xml", |b| {
91-
b.iter(|| {
92-
parse_document(TEST_WRITER_INDENT).unwrap();
93-
})
94-
});
95-
96-
// short, mix of attributes and text, lots of escapes
97-
group.bench_function("sample_1.xml", |b| {
98-
b.iter(|| {
99-
parse_document(SAMPLE_1).unwrap();
100-
})
101-
});
102-
103-
// medium length, lots of attributes, short attributes, few escapes
104-
group.bench_function("linescore.xml", |b| {
105-
b.iter(|| {
106-
parse_document(LINESCORE).unwrap();
107-
})
108-
});
109-
110-
// short, lots of namespaces, no escapes
111-
group.bench_function("sample_ns.xml", |b| {
112-
b.iter(|| {
113-
parse_document(SAMPLE_NS).unwrap();
114-
})
115-
});
116-
117-
// long, few attributes, mix of attribute lengths, escapes in text content
118-
group.bench_function("sample_rss.xml", |b| {
119-
b.iter(|| {
120-
parse_document(SAMPLE_RSS).unwrap();
121-
})
122-
});
123-
124-
// long, lots of attributes, short attributes, no text, no escapes
125-
group.bench_function("players.xml", |b| {
126-
b.iter(|| {
127-
parse_document(PLAYERS).unwrap();
128-
})
129-
});
47+
let inputs = [
48+
// long, mix of attributes and text, not much escaping, mix of attribute lengths, some namespaces
49+
("rpm_primary.xml", RPM_PRIMARY),
50+
// long, mix of attributes and text, not much escaping, mix of attribute lengths, some namespaces
51+
("rpm_primary2.xml", RPM_PRIMARY2),
52+
// long, mostly medium-length text elements, not much escaping
53+
("rpm_filelists.xml", RPM_FILELISTS),
54+
// long, mix of attributes and text, lots of escaping (both entity and char literal), long attributes
55+
("rpm_other.xml", RPM_OTHER),
56+
// long, mix of attributes and text, not much escaping, lots of non-ascii characters, lots of namespaces
57+
("libreoffice_document.fodt", LIBREOFFICE_DOCUMENT),
58+
// medium length, mostly empty tags, a few short attributes per element, no escaping
59+
("document.xml", DOCUMENT),
60+
// medium length, lots of namespaces, no escaping
61+
("test_writer_ident.xml", TEST_WRITER_INDENT),
62+
// short, mix of attributes and text, lots of escapes
63+
("sample_1.xml", SAMPLE_1),
64+
// medium length, lots of attributes, short attributes, few escapes
65+
("linescore.xml", LINESCORE),
66+
// short, lots of namespaces, no escapes
67+
("sample_ns.xml", SAMPLE_NS),
68+
// long, few attributes, mix of attribute lengths, escapes in text content
69+
("sample_rss.xml", SAMPLE_RSS),
70+
// long, lots of attributes, short attributes, no text, no escapes
71+
("players.xml", PLAYERS),
72+
];
73+
74+
for (id, data) in inputs.iter() {
75+
group.throughput(Throughput::Bytes(data.len() as u64));
76+
group.bench_with_input(*id, *data, |b, input| {
77+
b.iter(|| parse_document(input).unwrap())
78+
});
79+
}
13080

13181
group.finish();
13282
}

0 commit comments

Comments
 (0)