diff --git a/Cargo.toml b/Cargo.toml index 8943c39f..1379773d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ memchr = "2.1" # required, `dev-dependencies` are not used). `criterion` 0.6 has msrv = 1.80, so # we cannot check minimal versions with it. We allow to use `criterion` 0.4 for that # See https://github.com/rust-lang/cargo/issues/10958 -criterion = ">=0.4,<0.8" +criterion = ">=0.4,<0.9" pretty_assertions = "1.4" regex = "1" # https://github.com/serde-rs/serde/issues/1904 is fixed since 1.0.206 @@ -47,6 +47,11 @@ tokio-test = "0.4" [lib] bench = false +[profile.bench] +# For better information from cargo flamegraph +debug = true +lto = true + [[bench]] name = "microbenches" harness = false diff --git a/compare/Cargo.toml b/compare/Cargo.toml index 89eaea94..003a9634 100644 --- a/compare/Cargo.toml +++ b/compare/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dev-dependencies] -criterion = { version = "0.7", features = ["html_reports"] } +criterion = { version = "0.8", features = ["html_reports"] } markup5ever = "0.36" # maybe_xml 0.11 regressed performance by x2, and because this was the fastest # XML parser, we keep benchmarking version 0.10 as well @@ -17,6 +17,7 @@ maybe_xml = "0.11" quick-xml = { path = "..", features = ["serialize"] } rapid-xml = "0.2" rusty_xml = { version = "0.3", package = "RustyXML" } +rxml = "0.13" serde-xml-rs = "0.8" xml_oxide = "0.3" xml-rs = "1.0" @@ -35,3 +36,8 @@ harness = false [[bench]] name = "serde" harness = false + +[profile.bench] +# For better information from cargo flamegraph +debug = true +lto = true diff --git a/compare/benches/low-level.rs b/compare/benches/low-level.rs index db37dd3f..470adb9d 100644 --- a/compare/benches/low-level.rs +++ b/compare/benches/low-level.rs @@ -180,6 +180,42 @@ fn low_level_comparison(c: &mut Criterion) { }, ); + group.bench_with_input(BenchmarkId::new("rxml:borrowed", filename), *data, |b, input| { + use rxml::{Event, Parser, Parse}; + + b.iter(|| { + let mut doc = input.as_bytes(); + let mut p = Parser::new(); + let mut count = black_box(0); + while doc.len() > 0 { + // true = doc contains the entire document + match p.parse(&mut doc, true).unwrap() { + Some(Event::StartElement(..)) => count += 1, + None => break, + _ => (), + } + } + assert_eq!(count, total_tags, "Overall tag count in {}", filename); + }) + }); + + group.bench_with_input(BenchmarkId::new("rxml:buffered", filename), *data, |b, input| { + use rxml::{as_eof_flag, Event, Reader}; + use std::io::BufReader; + + b.iter(|| { + let reader = BufReader::new(input.as_bytes()); + let mut reader = Reader::new(reader); + let mut count = black_box(0); + let result = as_eof_flag(reader.read_all(|event| match event { + Event::StartElement(..) => count += 1, + _ => (), + })); + assert_eq!(result.unwrap(), true); // true indicates eof + assert_eq!(count, total_tags, "Overall tag count in {}", filename); + }) + }); + group.bench_with_input(BenchmarkId::new("RustyXml", filename), *data, |b, input| { use rusty_xml::{Event, Parser};