Skip to content

Commit

Permalink
add serialization benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhbooth committed Oct 18, 2024
1 parent 6b99333 commit f5961e3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ trybuild = "1.0.96"
name = "prefix_sum"
harness = false

# TODO: Fix bench
# [[bench]]
# name = "image_compression"
# harness = false

[[bench]]
name = "image_compression"
name = "serialize"
harness = false
1 change: 1 addition & 0 deletions benches/image_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ fn mean(numbers: &[f64]) -> f64 {
}

fn compression_benchmark(c: &mut Criterion) {
// TODO: replace file path with in-memory image (or add an image that is safe to distribute with the codebase)
// https://qoiformat.org/benchmark/
let files = fs::read_dir("/home/rasputin/qoi_benchmark_images/screenshot_web/")
.unwrap()
Expand Down
44 changes: 44 additions & 0 deletions benches/serialize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use criterion::black_box;
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;
use rkyv::rancor::Error as RancorError;
use wprs::serialization::wayland::DataToTransfer;

// benchmark to make sure we stay performant at serializing/deserializing large buffers.
// this means there should be zero copy, zero validation.
fn serialization_benchmark(c: &mut Criterion) {
let i: u32 = 100 * 1024 * 1024;
let buf = (0..i).map(|i| (i % 256) as u8).collect::<Vec<_>>();
let message = DataToTransfer(buf);

c.bench_function("serialize", |b| {
b.iter(|| black_box(rkyv::to_bytes::<RancorError>(&message)));
});

let archived_message = rkyv::to_bytes::<RancorError>(&message).unwrap();
c.bench_function("deserialize", |b| {
b.iter(|| {
black_box(rkyv::from_bytes::<DataToTransfer, RancorError>(
&archived_message[..],
))
});
});
}

criterion_group!(benches, serialization_benchmark);
criterion_main!(benches);

0 comments on commit f5961e3

Please sign in to comment.