Skip to content

Commit

Permalink
add pot to benchmarks (#53)
Browse files Browse the repository at this point in the history
Co-authored-by: GloopShlugger <Olli>
  • Loading branch information
GloopShlugger committed Aug 30, 2023
1 parent 4784e48 commit c572f0b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ nanoserde = {version = "0.1.33", optional = true }
parity-scale-codec = { version = "3.5.0", features = ["full"], optional = true }
parity-scale-codec-derive = { version = "3.1.4", optional = true }
postcard = { version = "1.0.4", features = ["alloc"], optional = true }
pot = { version = "3.0.0", optional = true }
prost = { version = "0.11.9", optional = true }
rand = "0.8.5"
rkyv = { version = "0.7.41", features = ["validation"], optional = true }
Expand Down Expand Up @@ -107,6 +108,7 @@ default = [
"nanoserde",
"scale",
"postcard",
"pot",
"prost",
"prost-build",
"rkyv",
Expand Down
14 changes: 14 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use rust_serialization_benchmark::bench_nanoserde;
use rust_serialization_benchmark::bench_parity_scale_codec;
#[cfg(feature = "postcard")]
use rust_serialization_benchmark::bench_postcard;
#[cfg(feature = "pot")]
use rust_serialization_benchmark::bench_pot;
#[cfg(feature = "prost")]
use rust_serialization_benchmark::bench_prost;
#[cfg(feature = "rkyv")]
Expand Down Expand Up @@ -158,6 +160,9 @@ fn bench_log(c: &mut Criterion) {
#[cfg(feature = "postcard")]
bench_postcard::bench(BENCH, c, &data);

#[cfg(feature = "pot")]
bench_pot::bench(BENCH, c, &data);

#[cfg(feature = "prost")]
bench_prost::bench(BENCH, c, &data);

Expand Down Expand Up @@ -314,6 +319,9 @@ fn bench_mesh(c: &mut Criterion) {
#[cfg(feature = "postcard")]
bench_postcard::bench(BENCH, c, &data);

#[cfg(feature = "pot")]
bench_pot::bench(BENCH, c, &data);

#[cfg(feature = "prost")]
bench_prost::bench(BENCH, c, &data);

Expand Down Expand Up @@ -461,6 +469,9 @@ fn bench_minecraft_savedata(c: &mut Criterion) {
#[cfg(feature = "postcard")]
bench_postcard::bench(BENCH, c, &data);

#[cfg(feature = "pot")]
bench_pot::bench(BENCH, c, &data);

#[cfg(feature = "prost")]
bench_prost::bench(BENCH, c, &data);

Expand Down Expand Up @@ -612,6 +623,9 @@ fn bench_mk48(c: &mut Criterion) {
#[cfg(feature = "postcard")]
bench_postcard::bench(BENCH, c, &data);

#[cfg(feature = "pot")]
bench_pot::bench(BENCH, c, &data);

#[cfg(feature = "prost")]
bench_prost::bench(BENCH, c, &data);

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

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

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

let mut serialize_buffer = vec![0; BUFFER_LEN];
group.bench_function("serialize", |b| {
b.iter(|| {
black_box(
pot::to_writer(black_box(&data), black_box(serialize_buffer.as_mut_slice()))
.unwrap(),
);
})
});

let deserialize_buffer = pot::to_vec(&data).unwrap();

group.bench_function("deserialize", |b| {
b.iter(|| {
black_box(pot::from_slice::<T>(black_box(&deserialize_buffer)).unwrap());
})
});

crate::bench_size(name, "pot", deserialize_buffer.as_slice());

group.finish();
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub mod bench_nanoserde;
pub mod bench_parity_scale_codec;
#[cfg(feature = "postcard")]
pub mod bench_postcard;
#[cfg(feature = "pot")]
pub mod bench_pot;
#[cfg(feature = "prost")]
pub mod bench_prost;
#[cfg(feature = "rkyv")]
Expand Down

0 comments on commit c572f0b

Please sign in to comment.