From acf605db4258ddeebe9cf50b0f82040e569825f2 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 2 Dec 2023 00:51:05 +0500 Subject: [PATCH 1/3] Run `cargo fmt` in compare project --- compare/benches/bench.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/compare/benches/bench.rs b/compare/benches/bench.rs index 04284340..26ac968a 100644 --- a/compare/benches/bench.rs +++ b/compare/benches/bench.rs @@ -58,12 +58,12 @@ fn low_level_comparison(c: &mut Criterion) { *data, |b, input| { b.iter(|| { - let mut r = Reader::from_reader(input.as_bytes()); - r.config_mut().check_end_names = false; + let mut reader = Reader::from_reader(input.as_bytes()); + reader.config_mut().check_end_names = false; let mut count = criterion::black_box(0); let mut buf = Vec::new(); loop { - match r.read_event_into(&mut buf) { + match reader.read_event_into(&mut buf) { Ok(Event::Start(_)) | Ok(Event::Empty(_)) => count += 1, Ok(Event::Eof) => break, _ => (), @@ -79,8 +79,8 @@ fn low_level_comparison(c: &mut Criterion) { BenchmarkId::new("maybe_xml", filename), *data, |b, input| { - use maybe_xml::Lexer; use maybe_xml::token::Ty; + use maybe_xml::Lexer; b.iter(|| { let lexer = Lexer::from_slice(input.as_bytes()); @@ -272,7 +272,8 @@ fn serde_comparison(c: &mut Criterion) { } b.iter(|| { - let rss: Rss = criterion::black_box(quick_xml::de::from_str(input).unwrap()); + let rss: Rss = + criterion::black_box(quick_xml::de::from_str(input).unwrap()); assert_eq!(rss.channel.items.len(), 99); }) }, @@ -307,7 +308,8 @@ fn serde_comparison(c: &mut Criterion) { } b.iter(|| { - let rss: Rss = criterion::black_box(serde_xml_rs::from_str(input).unwrap()); + let rss: Rss = + criterion::black_box(serde_xml_rs::from_str(input).unwrap()); assert_eq!(rss.channel.items.len(), 99); }) }, From a5219e9b89d106c088551facd61a382eafe1054c Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 2 Dec 2023 00:54:31 +0500 Subject: [PATCH 2/3] Add borrowed variant of quick-xml to compare benchmark quick-xml was benchmarked in buffered mode which a bit unfair --- compare/benches/bench.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/compare/benches/bench.rs b/compare/benches/bench.rs index 26ac968a..9057c3fb 100644 --- a/compare/benches/bench.rs +++ b/compare/benches/bench.rs @@ -54,7 +54,27 @@ fn low_level_comparison(c: &mut Criterion) { group.throughput(Throughput::Bytes(data.len() as u64)); group.bench_with_input( - BenchmarkId::new("quick_xml", filename), + BenchmarkId::new("quick_xml:borrowed", filename), + *data, + |b, input| { + b.iter(|| { + let mut reader = Reader::from_str(input); + reader.config_mut().check_end_names = false; + let mut count = criterion::black_box(0); + loop { + match reader.read_event() { + Ok(Event::Start(_)) | Ok(Event::Empty(_)) => count += 1, + Ok(Event::Eof) => break, + _ => (), + } + } + assert_eq!(count, total_tags, "Overall tag count in {}", filename); + }) + }, + ); + + group.bench_with_input( + BenchmarkId::new("quick_xml:buffered", filename), *data, |b, input| { b.iter(|| { From 82cc0dae1a051df25f5235466681fa37e42ebabb Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 2 Dec 2023 00:55:31 +0500 Subject: [PATCH 3/3] Update maybe_xml to the latest 0.10.1 --- compare/Cargo.toml | 2 +- compare/benches/bench.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compare/Cargo.toml b/compare/Cargo.toml index 8390b31e..c7f87163 100644 --- a/compare/Cargo.toml +++ b/compare/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" [dev-dependencies] criterion = { version = "0.5", features = ["html_reports"] } -maybe_xml = "0.6" +maybe_xml = "0.10.1" quick-xml = { path = "..", features = ["serialize"] } rapid-xml = "0.2" rusty_xml = { version = "0.3", package = "RustyXML" } diff --git a/compare/benches/bench.rs b/compare/benches/bench.rs index 9057c3fb..a091ff06 100644 --- a/compare/benches/bench.rs +++ b/compare/benches/bench.rs @@ -100,13 +100,13 @@ fn low_level_comparison(c: &mut Criterion) { *data, |b, input| { use maybe_xml::token::Ty; - use maybe_xml::Lexer; + use maybe_xml::Reader; b.iter(|| { - let lexer = Lexer::from_slice(input.as_bytes()); + let reader = Reader::from_str(input); let mut count = criterion::black_box(0); - for token in lexer.into_iter() { + for token in reader.into_iter() { match token.ty() { Ty::StartTag(_) | Ty::EmptyElementTag(_) => count += 1, _ => (),