Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quick-xml to benchmarks #34

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,26 @@ bson = { version = "2.0", git = "https://github.com/djkoloski/bson-rust", branch
bytecheck = { version = "0.6.8", optional = true }
bytemuck = { version = "1.10.0", optional = true }
capnp = { version = "0.14.8", optional = true }
criterion = "0.3.6"
criterion = "0.4.0"
dlhn = { version = "0.1.1", optional = true }
flatbuffers = { version = "2.1.2", optional = true }
libflate = "1.2.0"
nachricht-serde = { version = "0.4.0", optional = true }
parity-scale-codec = { version = "3.2.1", features = ["full"], optional = true }
parity-scale-codec-derive = { version = "3.1.3", optional = true }
postcard = { version = "1.0.1", features = ["alloc"], optional = true }
prost = { version = "0.10.4", optional = true }
prost = { version = "0.11.0", optional = true }
rand = "0.8.5"
rkyv = { version = "0.7.39", features = ["validation"], optional = true }
rmp-serde = { version = "1.1.0", optional = true }
ron = { version = "0.7.1", optional = true }
ron = { version = "0.8.0", optional = true }
serde = { version = "1.0.140", features = ["derive"], optional = true }
serde_bare = { version = "0.5.0", optional = true }
serde_cbor = { version = "0.11.2", optional = true }
serde_json = { version = "1.0.82", optional = true }
simd-json = { version = "0.6.0", optional = true }
speedy = { version = "0.8.2", optional = true }
quick-xml = { path = "../../rpm-dev/quick-xml", features = ["serialize"], optional = true }
zstd = "0.11.2"

[features]
Expand Down Expand Up @@ -71,6 +72,7 @@ default = [
"serde_json",
"simd-json",
"speedy",
"quick-xml"
]

scale = ["parity-scale-codec", "parity-scale-codec-derive"]
Expand All @@ -83,7 +85,7 @@ bebop-tools = "2.4.5"
capnp = "0.14.8"
capnpc = "0.14.9"
flatc-rust = "0.2.0"
prost-build = "0.10.4"
prost-build = "0.11.1"

[[bench]]
name = "bench"
Expand Down
15 changes: 13 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ use rust_serialization_benchmark::bench_serde_json;
use rust_serialization_benchmark::bench_simd_json;
#[cfg(feature = "speedy")]
use rust_serialization_benchmark::bench_speedy;
#[cfg(feature = "quick-xml")]
use rust_serialization_benchmark::bench_quickxml;
use rust_serialization_benchmark::generate_vec;

fn bench_log(c: &mut Criterion) {
Expand Down Expand Up @@ -179,6 +181,9 @@ fn bench_log(c: &mut Criterion) {
#[cfg(feature = "speedy")]
bench_speedy::bench(BENCH, c, &data);

#[cfg(feature = "quick-xml")]
bench_quickxml::bench(BENCH, c, &data);

// Doesn't use a closure due to ICE in rustc. Probably related to https://github.com/rust-lang/rust/issues/86703
#[cfg(feature = "alkahest")]
bench_alkahest::bench(BENCH, c, &data, read_alkahest_log);
Expand Down Expand Up @@ -318,6 +323,9 @@ fn bench_mesh(c: &mut Criterion) {
#[cfg(feature = "speedy")]
bench_speedy::bench(BENCH, c, &data);

#[cfg(feature = "quick-xml")]
bench_quickxml::bench(BENCH, c, &data);

// Doesn't use a closure due to ICE in rustc. Probably related to https://github.com/rust-lang/rust/issues/86703
#[cfg(feature = "alkahest")]
bench_alkahest::bench(BENCH, c, &data, read_alkahest_mesh);
Expand Down Expand Up @@ -459,6 +467,9 @@ fn bench_minecraft_savedata(c: &mut Criterion) {
#[cfg(feature = "speedy")]
bench_speedy::bench(BENCH, c, &data);

#[cfg(feature = "quick-xml")]
bench_quickxml::bench(BENCH, c, &data);

#[cfg(feature = "alkahest")]
bench_alkahest::bench(BENCH, c, &data, read_alkahest_minecraft_savedata);
}
Expand All @@ -476,8 +487,8 @@ fn read_alkahest_minecraft_savedata<'a>(
}

pub fn criterion_benchmark(c: &mut Criterion) {
bench_log(c);
bench_mesh(c);
// bench_log(c);
// bench_mesh(c);
bench_minecraft_savedata(c);
}

Expand Down
44 changes: 44 additions & 0 deletions src/bench_quickxml.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use serde::{Serialize, Deserialize};
use criterion::{black_box, Criterion};
use quick_xml;

pub fn bench<T>(name: &'static str, c: &mut Criterion, data: &T)
where
T: Serialize + for<'de> Deserialize<'de>,
{
const BUFFER_LEN: usize = 50_000_000;

let mut group = c.benchmark_group(format!("{}/serde_quickxml", name));

let mut serialize_buffer = String::with_capacity(BUFFER_LEN);
group.bench_function("serialize", |b| {
b.iter(|| {
black_box(
quick_xml::se::to_writer(
black_box(&mut serialize_buffer),
black_box(&data),
)
.unwrap()
);
})
});

let mut deserialize_buffer = String::new();
quick_xml::se::to_writer(&mut deserialize_buffer, &data).unwrap();
println!("{}", &deserialize_buffer);


group.bench_function("deserialize", |b| {
b.iter(|| {
black_box(
quick_xml::de::from_reader::<&[u8], T>(black_box(&deserialize_buffer.as_bytes()))
.unwrap()
);
})
});

println!("{}/serde_quickxml/size {}", name, deserialize_buffer.len());
println!("{}/serde_quickxml/zlib {}", name, crate::zlib_size(deserialize_buffer.as_bytes()));

group.finish();
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub mod bench_serde_json;
pub mod bench_simd_json;
#[cfg(feature = "speedy")]
pub mod bench_speedy;
#[cfg(feature = "quick-xml")]
pub mod bench_quickxml;
pub mod datasets;

use core::{mem, ops};
Expand Down