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

Upgrade criterion to 0.5.1, reorganize benchmarks #468

Merged
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
8 changes: 2 additions & 6 deletions rbx_binary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ profiling = "1.0.6"
zstd = "0.13.2"

[dev-dependencies]
criterion = "0.3.5"
criterion = "0.5.1"
env_logger = "0.9.0"
heck = "0.4.0"
insta = { version = "1.14.1", features = ["yaml"] }
serde = { version = "1.0.137", features = ["derive"] }

[[bench]]
name = "deserializer"
harness = false

[[bench]]
name = "serializer"
name = "suite"
harness = false
Binary file removed rbx_binary/bench-files/parts-10000.rbxm
Binary file not shown.
55 changes: 0 additions & 55 deletions rbx_binary/benches/deserializer.rs

This file was deleted.

Binary file added rbx_binary/benches/files/parts-1000.rbxm
Binary file not shown.
48 changes: 0 additions & 48 deletions rbx_binary/benches/serializer.rs

This file was deleted.

43 changes: 43 additions & 0 deletions rbx_binary/benches/suite/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
mod util;

use crate::util::bench;
use criterion::{criterion_group, criterion_main, Criterion, SamplingMode};

pub fn folders_100(c: &mut Criterion) {
bench(
&mut c.benchmark_group("100 Folders"),
include_bytes!("../files/folders-100.rbxm"),
)
}

pub fn deep_folders_100(c: &mut Criterion) {
bench(
&mut c.benchmark_group("100 Deep Folders"),
include_bytes!("../files/deep-folders-100.rbxm"),
)
}

pub fn modulescripts_100_lines_100(c: &mut Criterion) {
bench(
&mut c.benchmark_group("100 100-line ModuleScripts"),
include_bytes!("../files/modulescripts-100-lines-100.rbxm"),
)
}

pub fn parts_1000(c: &mut Criterion) {
bench(
c.benchmark_group("1,000 Parts")
.sampling_mode(SamplingMode::Flat),
include_bytes!("../files/parts-1000.rbxm"),
)
}

criterion_group!(
bench_suite,
folders_100,
deep_folders_100,
modulescripts_100_lines_100,
parts_1000,
);

criterion_main!(bench_suite);
37 changes: 37 additions & 0 deletions rbx_binary/benches/suite/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use criterion::{measurement::Measurement, BatchSize, BenchmarkGroup, Throughput};

pub(crate) fn bench<T: Measurement>(group: &mut BenchmarkGroup<T>, bench_file: &'static [u8]) {
serialize_bench(group, bench_file);
deserialize_bench(group, bench_file);
}

fn serialize_bench<T: Measurement>(group: &mut BenchmarkGroup<T>, buffer: &[u8]) {
let tree = rbx_binary::from_reader(buffer).unwrap();
let root_ref = tree.root_ref();
let mut buffer = Vec::new();

rbx_binary::to_writer(&mut buffer, &tree, &[root_ref]).unwrap();
let buffer_len = buffer.len();

group
.throughput(Throughput::Bytes(buffer_len as u64))
.bench_function("Serialize", |b| {
b.iter_batched(
|| Vec::with_capacity(buffer_len),
|mut buffer: Vec<u8>| {
rbx_binary::to_writer(&mut buffer, &tree, &[root_ref]).unwrap();
},
BatchSize::SmallInput,
)
});
}

fn deserialize_bench<T: Measurement>(group: &mut BenchmarkGroup<T>, buffer: &[u8]) {
group
.throughput(Throughput::Bytes(buffer.len() as u64))
.bench_function("Deserialize", |bencher| {
bencher.iter(|| {
rbx_binary::from_reader(buffer).unwrap();
});
});
}