summaryrefslogtreecommitdiff
path: root/benchmarks/quick-xml
diff options
context:
space:
mode:
authorsteven-vd <steven@vandorp.lu>2026-08-16 15:00:32 +0200
committersteven-vd <steven@vandorp.lu>2026-08-17 09:31:42 +0200
commitee081ca70322cd01d0642fdb1860e6bfbfb48e85 (patch)
tree295fdba93b08b24562c6d49e971bbf3425eac50c /benchmarks/quick-xml
Initial commitHEAD0.1.0master
Diffstat (limited to 'benchmarks/quick-xml')
-rw-r--r--benchmarks/quick-xml/.env/build.sh5
-rw-r--r--benchmarks/quick-xml/.env/debug.sh8
-rw-r--r--benchmarks/quick-xml/.gitignore1
-rw-r--r--benchmarks/quick-xml/Cargo.lock25
-rw-r--r--benchmarks/quick-xml/Cargo.toml14
-rw-r--r--benchmarks/quick-xml/benchmark-results.xml26
-rw-r--r--benchmarks/quick-xml/src/count_highway_crossings.rs74
-rw-r--r--benchmarks/quick-xml/src/main.rs39
-rw-r--r--benchmarks/quick-xml/src/pubmed_len.rs82
9 files changed, 274 insertions, 0 deletions
diff --git a/benchmarks/quick-xml/.env/build.sh b/benchmarks/quick-xml/.env/build.sh
new file mode 100644
index 0000000..09ce8e7
--- /dev/null
+++ b/benchmarks/quick-xml/.env/build.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+#RUSTFLAGS="-C target-cpu=native" cargo build --release
+cargo build --release
+
diff --git a/benchmarks/quick-xml/.env/debug.sh b/benchmarks/quick-xml/.env/debug.sh
new file mode 100644
index 0000000..23f310e
--- /dev/null
+++ b/benchmarks/quick-xml/.env/debug.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+set -xe
+
+. .env/build.sh
+
+./target/release/quick-xml-bench
+
diff --git a/benchmarks/quick-xml/.gitignore b/benchmarks/quick-xml/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/benchmarks/quick-xml/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/benchmarks/quick-xml/Cargo.lock b/benchmarks/quick-xml/Cargo.lock
new file mode 100644
index 0000000..33fc320
--- /dev/null
+++ b/benchmarks/quick-xml/Cargo.lock
@@ -0,0 +1,25 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "memchr"
+version = "2.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
+
+[[package]]
+name = "quick-xml"
+version = "0.41.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "quick-xml-bench"
+version = "0.1.0"
+dependencies = [
+ "quick-xml",
+]
diff --git a/benchmarks/quick-xml/Cargo.toml b/benchmarks/quick-xml/Cargo.toml
new file mode 100644
index 0000000..fb1a66b
--- /dev/null
+++ b/benchmarks/quick-xml/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "quick-xml-bench"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+quick-xml = "0.41.0"
+
+[profile.release]
+opt-level = 3
+lto = true
+codegen-units = 1
+panic = "abort"
+
diff --git a/benchmarks/quick-xml/benchmark-results.xml b/benchmarks/quick-xml/benchmark-results.xml
new file mode 100644
index 0000000..b40abb0
--- /dev/null
+++ b/benchmarks/quick-xml/benchmark-results.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<benchmarks library="quick-xml">
+ <benchmark name="count_highway_crossings">
+ <res>229</res>
+ <time unit="ns">510085538</time>
+ <throughput unit="MiB/s">892.6964484824999</throughput>
+ <energy-consumption unit="J/GiB">33.06487793812473</energy-consumption>
+ </benchmark>
+ <benchmark name="count_highway_crossings_cheat_and_early_out">
+ <res>229</res>
+ <time unit="ns">362069942</time>
+ <throughput unit="MiB/s">1257.634217520562</throughput>
+ <energy-consumption unit="J/GiB">23.364528672792822</energy-consumption>
+ </benchmark>
+ <benchmark name="pubmed_len">
+ <res>74757</res>
+ <time unit="ns">173540</time>
+ <throughput unit="MiB/s">847.5963209608781</throughput>
+ </benchmark>
+ <benchmark name="pubmed_len_with_entities">
+ <res>74757</res>
+ <time unit="ns">195641</time>
+ <throughput unit="MiB/s">751.8458070626851</throughput>
+ </benchmark>
+</benchmarks>
+
diff --git a/benchmarks/quick-xml/src/count_highway_crossings.rs b/benchmarks/quick-xml/src/count_highway_crossings.rs
new file mode 100644
index 0000000..9b68142
--- /dev/null
+++ b/benchmarks/quick-xml/src/count_highway_crossings.rs
@@ -0,0 +1,74 @@
+use quick_xml::events::Event;
+use quick_xml::Reader;
+
+pub fn count_highway_crossings(buffer: &[u8]) -> usize {
+ let mut reader = Reader::from_reader(buffer);
+ reader.config_mut().check_end_names = false;
+
+ let mut count = 0usize;
+ let mut in_node = false;
+
+ loop {
+ match reader.read_event() {
+ Ok(Event::Eof) => break,
+
+ Ok(Event::Start(e)) if e.name().as_ref() == b"node" => {
+ in_node = true;
+ }
+
+ Ok(Event::End(e)) if e.name().as_ref() == b"node" => {
+ in_node = false;
+ }
+
+ Ok(Event::Start(e)) | Ok(Event::Empty(e))
+ if in_node && e.name().as_ref() == b"tag" =>
+ {
+ let mut attrs = e.attributes();
+ if attrs.next().unwrap().unwrap().value.as_ref() == b"highway"
+ && attrs.next().unwrap().unwrap().value.as_ref() == b"crossing" {
+ count += 1;
+ }
+ }
+
+ Ok(_) => {}
+ Err(_) => break,
+ }
+ }
+
+ count
+}
+
+pub fn count_highway_crossings_cheat_and_early_out(buffer: &[u8]) -> usize {
+ let mut reader = Reader::from_reader(buffer);
+ reader.config_mut().check_end_names = false;
+
+ let mut count = 0usize;
+
+ loop {
+ match reader.read_event() {
+ Ok(Event::Eof) => break,
+
+ Ok(Event::Start(e)) | Ok(Event::Empty(e))
+ if e.name().as_ref() == b"tag" =>
+ {
+ let mut attrs = e.attributes();
+ if attrs.next().unwrap().unwrap().value.as_ref() == b"highway"
+ && attrs.next().unwrap().unwrap().value.as_ref() == b"crossing" {
+ count += 1;
+ }
+ }
+
+ Ok(Event::Start(e)) | Ok(Event::Empty(e))
+ if e.name().as_ref() == b"way" =>
+ {
+ break;
+ }
+
+ Ok(_) => {}
+ Err(_) => break,
+ }
+ }
+
+ count
+}
+
diff --git a/benchmarks/quick-xml/src/main.rs b/benchmarks/quick-xml/src/main.rs
new file mode 100644
index 0000000..fef0ee7
--- /dev/null
+++ b/benchmarks/quick-xml/src/main.rs
@@ -0,0 +1,39 @@
+use std::fs;
+
+#[path = "../../harness.rs"]
+mod harness;
+use harness::*;
+
+mod pubmed_len;
+use pubmed_len::*;
+mod count_highway_crossings;
+use count_highway_crossings::*;
+
+macro_rules! bench {
+ ($f:expr, $buffer:expr, $out:expr) => {
+ bench(String::from(stringify!($f)), $f, $buffer.as_slice(), &mut $out)
+ };
+}
+
+fn main() {
+ let mut out = String::from(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
+ <benchmarks library=\"quick-xml\">\n",
+ );
+
+ if true {
+ let buffer = fs::read("../../dat/yellowstone.osm").expect("Failed to read file");
+ bench!(count_highway_crossings, buffer, out);
+ bench!(count_highway_crossings_cheat_and_early_out, buffer, out);
+ }
+
+ if true {
+ let buffer = fs::read("../../dat/PMC176545.xml").expect("Failed to read file");
+ bench!(pubmed_len, buffer, out);
+ bench!(pubmed_len_with_entities, buffer, out);
+ }
+
+ out.push_str("</benchmarks>\n\n");
+ std::fs::write("benchmark-results.xml", out).unwrap();
+}
+
diff --git a/benchmarks/quick-xml/src/pubmed_len.rs b/benchmarks/quick-xml/src/pubmed_len.rs
new file mode 100644
index 0000000..592e6e3
--- /dev/null
+++ b/benchmarks/quick-xml/src/pubmed_len.rs
@@ -0,0 +1,82 @@
+use quick_xml::events::Event;
+use quick_xml::Reader;
+
+pub fn pubmed_len(buffer: &[u8]) -> usize {
+ let mut reader = Reader::from_reader(buffer);
+ let mut in_content = 0usize;
+ let mut total = 0usize;
+
+ loop {
+ match reader.read_event() {
+ Ok(Event::Start(e)) => {
+ if in_content != 0 {
+ in_content += 1;
+ } else {
+ if e.name().as_ref() == b"abstract"
+ || e.name().as_ref()== b"body" {
+ in_content = 1;
+ }
+ }
+ }
+
+ Ok(Event::End(_)) => {
+ if in_content != 0 {
+ in_content -= 1;
+ }
+ }
+
+ Ok(Event::Text(e)) => {
+ if in_content != 0 {
+ total += e.len();
+ }
+ }
+
+ Ok(Event::Eof) => break,
+
+ Ok(_) => {}
+ Err(_) => unreachable!("buffer is valid PMC XML"),
+ }
+ }
+
+ total
+}
+
+pub fn pubmed_len_with_entities(buffer: &[u8]) -> usize {
+ let mut reader = Reader::from_reader(buffer);
+ let mut in_content = 0usize;
+ let mut total = 0usize;
+
+ loop {
+ match reader.read_event() {
+ Ok(Event::Start(e)) => {
+ if in_content != 0 {
+ in_content += 1;
+ } else if e.name().as_ref() == b"abstract"
+ || e.name().as_ref() == b"body"
+ {
+ in_content = 1;
+ }
+ }
+
+ Ok(Event::End(_)) => {
+ if in_content != 0 {
+ in_content -= 1;
+ }
+ }
+
+ Ok(Event::Text(e)) => {
+ if in_content != 0 {
+ total += e.decode().unwrap().len();
+ }
+ }
+
+ Ok(Event::Eof) => break,
+
+ Ok(_) => {}
+ Err(_) => unreachable!("buffer is valid PMC XML"),
+ }
+ }
+
+ total
+}
+