From e8151669365d197c52064c8b07186690dae4c781 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sun, 8 May 2022 01:09:47 +0500 Subject: [PATCH 1/6] Add xml5ever to comparison It is number 17 (at time of commit) in "Parser implementations" topic with 137 usages (5 direct) according to https://lib.rs/crates/xml5ever --- compare/Cargo.toml | 1 + compare/benches/bench.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/compare/Cargo.toml b/compare/Cargo.toml index 50979fef..0e75d403 100644 --- a/compare/Cargo.toml +++ b/compare/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" criterion = "0.3" quick-xml = { path = "..", features = ["serialize"] } xml-rs = "0.8" +xml5ever = "0.17" serde-xml-rs = "0.5" serde = { version = "1.0", features = [ "derive" ] } pretty_assertions = "1.2" diff --git a/compare/benches/bench.rs b/compare/benches/bench.rs index 476e4f45..ab81344d 100644 --- a/compare/benches/bench.rs +++ b/compare/benches/bench.rs @@ -29,6 +29,38 @@ fn low_level_comparison(c: &mut Criterion) { }) }); + group.bench_function("xml5ever", |b| { + use xml5ever::buffer_queue::BufferQueue; + use xml5ever::tokenizer::{TagKind, Token, TokenSink, XmlTokenizer}; + + struct Sink(usize); + impl TokenSink for Sink { + fn process_token(&mut self, token: Token) { + match token { + Token::TagToken(tag) if tag.kind == TagKind::StartTag => self.0 += 1, + Token::TagToken(tag) if tag.kind == TagKind::EmptyTag => self.0 += 1, + _ => (), + } + } + } + + // Copied from xml5ever benchmarks + // https://github.com/servo/html5ever/blob/429f23943b24f739b78f4d703620d7b1b526475b/xml5ever/benches/xml5ever.rs + b.iter(|| { + let sink = criterion::black_box(Sink(0)); + let mut tok = XmlTokenizer::new(sink, Default::default()); + let mut buffer = BufferQueue::new(); + buffer.push_back(SOURCE.into()); + let _ = tok.feed(&mut buffer); + tok.end(); + + assert_eq!( + tok.sink.0, 1550, + "Overall tag count in ./tests/sample_rss.xml" + ); + }) + }); + group.bench_function("xml_rs", |b| { b.iter(|| { let r = EventReader::new(SOURCE.as_bytes()); From 4a869de1f5aa0756223d46c7ae5a0fcea20c3e8e Mon Sep 17 00:00:00 2001 From: Mingun Date: Sun, 8 May 2022 01:17:09 +0500 Subject: [PATCH 2/6] Add xmlparser to comparison It is number 38 (at time of commit) in "Parser implementations" topic with 620 usages (15 direct) according to https://lib.rs/crates/xmlparser --- compare/Cargo.toml | 1 + compare/benches/bench.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/compare/Cargo.toml b/compare/Cargo.toml index 0e75d403..6e683b24 100644 --- a/compare/Cargo.toml +++ b/compare/Cargo.toml @@ -11,6 +11,7 @@ criterion = "0.3" quick-xml = { path = "..", features = ["serialize"] } xml-rs = "0.8" xml5ever = "0.17" +xmlparser = "0.13" serde-xml-rs = "0.5" serde = { version = "1.0", features = [ "derive" ] } pretty_assertions = "1.2" diff --git a/compare/benches/bench.rs b/compare/benches/bench.rs index ab81344d..4d39f942 100644 --- a/compare/benches/bench.rs +++ b/compare/benches/bench.rs @@ -29,6 +29,21 @@ fn low_level_comparison(c: &mut Criterion) { }) }); + group.bench_function("xmlparser", |b| { + use xmlparser::{Token, Tokenizer}; + + b.iter(|| { + let mut count = criterion::black_box(0); + for token in Tokenizer::from(SOURCE) { + match token { + Ok(Token::ElementStart { .. }) => count += 1, + _ => (), + } + } + assert_eq!(count, 1550, "Overall tag count in ./tests/sample_rss.xml"); + }) + }); + group.bench_function("xml5ever", |b| { use xml5ever::buffer_queue::BufferQueue; use xml5ever::tokenizer::{TagKind, Token, TokenSink, XmlTokenizer}; From 0755af95817476b3d4a2d75dc8bb843186aabf30 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 14 May 2022 22:26:41 +0500 Subject: [PATCH 3/6] Add xml_oxide to comparison It is number 143 (at time of commit) in "Parser implementations" topic without usages according to https://lib.rs/crates/xml_oxide --- compare/Cargo.toml | 1 + compare/benches/bench.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/compare/Cargo.toml b/compare/Cargo.toml index 6e683b24..5ad83f22 100644 --- a/compare/Cargo.toml +++ b/compare/Cargo.toml @@ -9,6 +9,7 @@ edition = "2018" [dev-dependencies] criterion = "0.3" quick-xml = { path = "..", features = ["serialize"] } +xml_oxide = "0.3" xml-rs = "0.8" xml5ever = "0.17" xmlparser = "0.13" diff --git a/compare/benches/bench.rs b/compare/benches/bench.rs index 4d39f942..14e65eb8 100644 --- a/compare/benches/bench.rs +++ b/compare/benches/bench.rs @@ -44,6 +44,26 @@ fn low_level_comparison(c: &mut Criterion) { }) }); + group.bench_function("xml_oxide", |b| { + use xml_oxide::sax::parser::Parser; + use xml_oxide::sax::Event; + + b.iter(|| { + let mut r = Parser::from_reader(SOURCE.as_bytes()); + + let mut count = criterion::black_box(0); + loop { + // Makes no progress if error is returned, so need unwrap() + match r.read_event().unwrap() { + Event::StartElement(_) => count += 1, + Event::EndDocument => break, + _ => (), + } + } + assert_eq!(count, 1550, "Overall tag count in ./tests/sample_rss.xml"); + }) + }); + group.bench_function("xml5ever", |b| { use xml5ever::buffer_queue::BufferQueue; use xml5ever::tokenizer::{TagKind, Token, TokenSink, XmlTokenizer}; From 53d292b62fb6bbdd278d1d07143e592da7a1c4fc Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 14 May 2022 23:04:21 +0500 Subject: [PATCH 4/6] Add rapid-xml to comparison It is number 320 (at time of commit) in "Parser implementations" topic without usages according to https://lib.rs/crates/rapid-xml --- compare/Cargo.toml | 1 + compare/benches/bench.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/compare/Cargo.toml b/compare/Cargo.toml index 5ad83f22..09f060ae 100644 --- a/compare/Cargo.toml +++ b/compare/Cargo.toml @@ -9,6 +9,7 @@ edition = "2018" [dev-dependencies] criterion = "0.3" quick-xml = { path = "..", features = ["serialize"] } +rapid-xml = "0.2" xml_oxide = "0.3" xml-rs = "0.8" xml5ever = "0.17" diff --git a/compare/benches/bench.rs b/compare/benches/bench.rs index 14e65eb8..6f1280be 100644 --- a/compare/benches/bench.rs +++ b/compare/benches/bench.rs @@ -29,6 +29,25 @@ fn low_level_comparison(c: &mut Criterion) { }) }); + group.bench_function("rapid-xml", |b| { + use rapid_xml::parser::{EventCode, Parser}; + + b.iter(|| { + let mut r = Parser::new(SOURCE.as_bytes()); + + let mut count = criterion::black_box(0); + loop { + // Makes no progress if error is returned, so need unwrap() + match r.next().unwrap().code() { + EventCode::StartTag => count += 1, + EventCode::Eof => break, + _ => (), + } + } + assert_eq!(count, 1550, "Overall tag count in ./tests/sample_rss.xml"); + }) + }); + group.bench_function("xmlparser", |b| { use xmlparser::{Token, Tokenizer}; @@ -151,6 +170,19 @@ fn serde_comparison(c: &mut Criterion) { }) }); + /* NOTE: Most parts of deserializer are not implemented yet, so benchmark failed + group.bench_function("rapid-xml", |b| { + use rapid_xml::de::Deserializer; + use rapid_xml::parser::Parser; + + b.iter(|| { + let mut r = Parser::new(SOURCE.as_bytes()); + let mut de = Deserializer::new(&mut r).unwrap(); + let rss = Rss::deserialize(&mut de).unwrap(); + assert_eq!(rss.channel.items.len(), 99); + }); + });*/ + group.bench_function("xml_rs", |b| { b.iter(|| { let rss: Rss = serde_xml_rs::from_str(SOURCE).unwrap(); From dda887991494c2d24f67d886c23a0fc01618d0b4 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 14 May 2022 23:33:13 +0500 Subject: [PATCH 5/6] Add maybe_xml to comparison It is number 264 (at time of commit) in "Parser implementations" topic without usages according to https://lib.rs/crates/maybe_xml --- compare/Cargo.toml | 1 + compare/benches/bench.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/compare/Cargo.toml b/compare/Cargo.toml index 09f060ae..f29ee9d6 100644 --- a/compare/Cargo.toml +++ b/compare/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dev-dependencies] criterion = "0.3" +maybe_xml = "0.2" quick-xml = { path = "..", features = ["serialize"] } rapid-xml = "0.2" xml_oxide = "0.3" diff --git a/compare/benches/bench.rs b/compare/benches/bench.rs index 6f1280be..c92a7481 100644 --- a/compare/benches/bench.rs +++ b/compare/benches/bench.rs @@ -29,6 +29,30 @@ fn low_level_comparison(c: &mut Criterion) { }) }); + group.bench_function("maybe_xml", |b| { + use maybe_xml::eval::recv::RecvEvaluator; + use maybe_xml::token::borrowed::Token; + + b.iter(|| { + let mut input = SOURCE.as_bytes(); + let mut eval = RecvEvaluator::new(); + + let mut count = criterion::black_box(0); + loop { + let consumed = eval.recv(input); + match eval.next_token() { + Ok(Some(Token::StartTag(_))) => count += 1, + Ok(Some(Token::EmptyElementTag(_))) => count += 1, + Ok(Some(Token::Eof)) => break, + Ok(Some(Token::EofWithBytesNotEvaluated(_))) => break, + _ => (), + } + input = &input[consumed..]; + } + assert_eq!(count, 1550, "Overall tag count in ./tests/sample_rss.xml"); + }) + }); + group.bench_function("rapid-xml", |b| { use rapid_xml::parser::{EventCode, Parser}; From d7781b10889a1f363823b17b2f6f317c954239b9 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sun, 15 May 2022 00:44:22 +0500 Subject: [PATCH 6/6] Add RustyXML to comparison Usages: 63 (16 direct) according to https://lib.rs/crates/RustyXML --- compare/Cargo.toml | 1 + compare/benches/bench.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/compare/Cargo.toml b/compare/Cargo.toml index f29ee9d6..9f649d31 100644 --- a/compare/Cargo.toml +++ b/compare/Cargo.toml @@ -11,6 +11,7 @@ criterion = "0.3" maybe_xml = "0.2" quick-xml = { path = "..", features = ["serialize"] } rapid-xml = "0.2" +rusty_xml = { version = "0.3", package = "RustyXML" } xml_oxide = "0.3" xml-rs = "0.8" xml5ever = "0.17" diff --git a/compare/benches/bench.rs b/compare/benches/bench.rs index c92a7481..fbb98a72 100644 --- a/compare/benches/bench.rs +++ b/compare/benches/bench.rs @@ -87,6 +87,24 @@ fn low_level_comparison(c: &mut Criterion) { }) }); + group.bench_function("RustyXML", |b| { + use rusty_xml::{Event, Parser}; + + b.iter(|| { + let mut r = Parser::new(); + r.feed_str(SOURCE); + + let mut count = criterion::black_box(0); + for event in r { + match event.unwrap() { + Event::ElementStart(_) => count += 1, + _ => (), + } + } + assert_eq!(count, 1550, "Overall tag count in ./tests/sample_rss.xml"); + }) + }); + group.bench_function("xml_oxide", |b| { use xml_oxide::sax::parser::Parser; use xml_oxide::sax::Event;