|
1 | | -use criterion::{self, criterion_group, Criterion}; |
| 1 | +use criterion::{self, criterion_group, Criterion, Throughput}; |
2 | 2 | use quick_xml::events::Event; |
3 | 3 | use quick_xml::Reader; |
4 | 4 | use quick_xml::Result as XmlResult; |
@@ -44,89 +44,39 @@ fn parse_document(doc: &[u8]) -> XmlResult<()> { |
44 | 44 | pub fn bench_fully_parse_document(c: &mut Criterion) { |
45 | 45 | let mut group = c.benchmark_group("fully_parse_document"); |
46 | 46 |
|
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 | + } |
130 | 80 |
|
131 | 81 | group.finish(); |
132 | 82 | } |
|
0 commit comments