@@ -2,50 +2,11 @@ use criterion::{self, criterion_group, criterion_main, BenchmarkId, Criterion, T
2
2
use pretty_assertions:: assert_eq;
3
3
use quick_xml:: events:: Event ;
4
4
use quick_xml:: reader:: Reader ;
5
- use serde:: Deserialize ;
6
- use serde_xml_rs;
7
5
use std:: hint:: black_box;
8
6
use xml:: reader:: { EventReader , XmlEvent } ;
9
7
10
- static RPM_PRIMARY : & str = include_str ! ( "../../tests/documents/rpm_primary.xml" ) ;
11
- static RPM_PRIMARY2 : & str = include_str ! ( "../../tests/documents/rpm_primary2.xml" ) ;
12
- static RPM_FILELISTS : & str = include_str ! ( "../../tests/documents/rpm_filelists.xml" ) ;
13
- static RPM_OTHER : & str = include_str ! ( "../../tests/documents/rpm_other.xml" ) ;
14
- static LIBREOFFICE_DOCUMENT : & str = include_str ! ( "../../tests/documents/libreoffice_document.fodt" ) ;
15
- static DOCUMENT : & str = include_str ! ( "../../tests/documents/document.xml" ) ;
16
- static TEST_WRITER_INDENT : & str = include_str ! ( "../../tests/documents/test_writer_indent.xml" ) ;
17
- static SAMPLE_1 : & str = include_str ! ( "../../tests/documents/sample_1.xml" ) ;
18
- static LINESCORE : & str = include_str ! ( "../../tests/documents/linescore.xml" ) ;
19
- static SAMPLE_RSS : & str = include_str ! ( "../../tests/documents/sample_rss.xml" ) ;
20
- static SAMPLE_NS : & str = include_str ! ( "../../tests/documents/sample_ns.xml" ) ;
21
- static PLAYERS : & str = include_str ! ( "../../tests/documents/players.xml" ) ;
22
-
23
- static TEST_FILES : [ ( & str , & str , usize ) ; 12 ] = [
24
- // long, mix of attributes and text, not much escaping, mix of attribute lengths, some namespaces
25
- ( "rpm_primary.xml" , RPM_PRIMARY , 369 ) ,
26
- // long, mix of attributes and text, not much escaping, mix of attribute lengths, some namespaces
27
- ( "rpm_primary2.xml" , RPM_PRIMARY2 , 116 ) ,
28
- // long, mostly medium-length text elements, not much escaping
29
- ( "rpm_filelists.xml" , RPM_FILELISTS , 184 ) ,
30
- // long, mix of attributes and text, lots of escaping (both entity and char literal), long attributes
31
- ( "rpm_other.xml" , RPM_OTHER , 145 ) ,
32
- // long, mix of attributes and text, not much escaping, lots of non-ascii characters, lots of namespaces
33
- ( "libreoffice_document.fodt" , LIBREOFFICE_DOCUMENT , 659 ) ,
34
- // medium length, mostly empty tags, a few short attributes per element, no escaping
35
- ( "document.xml" , DOCUMENT , 342 ) ,
36
- // medium length, lots of namespaces, no escaping
37
- ( "test_writer_ident.xml" , TEST_WRITER_INDENT , 34 ) ,
38
- // short, mix of attributes and text, lots of escapes
39
- ( "sample_1.xml" , SAMPLE_1 , 15 ) ,
40
- // medium length, lots of attributes, short attributes, few escapes
41
- ( "linescore.xml" , LINESCORE , 11 ) ,
42
- // short, lots of namespaces, no escapes
43
- ( "sample_ns.xml" , SAMPLE_NS , 11 ) ,
44
- // long, few attributes, mix of attribute lengths, escapes in text content
45
- ( "sample_rss.xml" , SAMPLE_RSS , 1550 ) ,
46
- // long, lots of attributes, short attributes, no text, no escapes
47
- ( "players.xml" , PLAYERS , 76 ) ,
48
- ] ;
8
+ mod common;
9
+ use common:: * ;
49
10
50
11
// Comparison of low-level APIs from several XML libraries
51
12
fn low_level_comparison ( c : & mut Criterion ) {
@@ -283,83 +244,5 @@ fn low_level_comparison(c: &mut Criterion) {
283
244
group. finish ( ) ;
284
245
}
285
246
286
- /// Runs benchmarks for several XML libraries using serde deserialization
287
- #[ allow( dead_code) ] // We do not use structs
288
- fn serde_comparison ( c : & mut Criterion ) {
289
- let mut group = c. benchmark_group ( "serde" ) ;
290
-
291
- #[ derive( Debug , Deserialize ) ]
292
- struct Rss < E > {
293
- channel : Channel < E > ,
294
- }
295
-
296
- #[ derive( Debug , Deserialize ) ]
297
- struct Channel < E > {
298
- title : String ,
299
- #[ serde( rename = "item" , default = "Vec::new" ) ]
300
- items : Vec < Item < E > > ,
301
- }
302
-
303
- #[ derive( Debug , Deserialize ) ]
304
- struct Item < E > {
305
- title : String ,
306
- link : String ,
307
- #[ serde( rename = "pubDate" ) ]
308
- pub_date : String ,
309
- enclosure : Option < E > ,
310
- }
311
-
312
- #[ derive( Debug , Deserialize ) ]
313
- struct Enclosure {
314
- #[ serde( rename = "@url" ) ]
315
- url : String ,
316
-
317
- #[ serde( rename = "@length" ) ]
318
- length : String ,
319
-
320
- #[ serde( rename = "@type" ) ]
321
- typ : String ,
322
- }
323
-
324
- group. throughput ( Throughput :: Bytes ( SAMPLE_RSS . len ( ) as u64 ) ) ;
325
-
326
- group. bench_with_input (
327
- BenchmarkId :: new ( "quick_xml" , "sample_rss.xml" ) ,
328
- SAMPLE_RSS ,
329
- |b, input| {
330
- b. iter ( || {
331
- let rss: Rss < Enclosure > = black_box ( quick_xml:: de:: from_str ( input) . unwrap ( ) ) ;
332
- assert_eq ! ( rss. channel. items. len( ) , 99 ) ;
333
- } )
334
- } ,
335
- ) ;
336
-
337
- /* NOTE: Most parts of deserializer are not implemented yet, so benchmark failed
338
- group.bench_with_input(BenchmarkId::new("rapid-xml", "sample_rss.xml"), SAMPLE_RSS, |b, input| {
339
- use rapid_xml::de::Deserializer;
340
- use rapid_xml::parser::Parser;
341
-
342
- b.iter(|| {
343
- let mut r = Parser::new(input.as_bytes());
344
- let mut de = Deserializer::new(&mut r).unwrap();
345
- let rss = black_box(Rss::deserialize(&mut de).unwrap());
346
- assert_eq!(rss.channel.items.len(), 99);
347
- });
348
- });*/
349
-
350
- group. bench_with_input (
351
- BenchmarkId :: new ( "xml_rs" , "sample_rss.xml" ) ,
352
- SAMPLE_RSS ,
353
- |b, input| {
354
- b. iter ( || {
355
- let rss: Rss < Enclosure > = black_box ( serde_xml_rs:: from_str ( input) . unwrap ( ) ) ;
356
- assert_eq ! ( rss. channel. items. len( ) , 99 ) ;
357
- } )
358
- } ,
359
- ) ;
360
-
361
- group. finish ( ) ;
362
- }
363
-
364
- criterion_group ! ( benches, low_level_comparison, serde_comparison) ;
247
+ criterion_group ! ( benches, low_level_comparison) ;
365
248
criterion_main ! ( benches) ;
0 commit comments