From 482c27bc8ded5c658134ace5dbfb205331554289 Mon Sep 17 00:00:00 2001 From: Kenneth Loeffler Date: Thu, 31 Oct 2024 15:35:03 +0000 Subject: [PATCH] Upgrade criterion to 0.5.1, reorganize benchmarks (#468) --- rbx_binary/Cargo.toml | 8 +-- rbx_binary/bench-files/parts-10000.rbxm | Bin 13406 -> 0 bytes rbx_binary/benches/deserializer.rs | 55 ------------------ .../files}/deep-folders-100.rbxm | Bin .../files}/folders-100.rbxm | Bin .../files}/modulescripts-100-lines-100.rbxm | Bin rbx_binary/benches/files/parts-1000.rbxm | Bin 0 -> 4261 bytes rbx_binary/benches/serializer.rs | 48 --------------- rbx_binary/benches/suite/main.rs | 43 ++++++++++++++ rbx_binary/benches/suite/util.rs | 37 ++++++++++++ 10 files changed, 82 insertions(+), 109 deletions(-) delete mode 100644 rbx_binary/bench-files/parts-10000.rbxm delete mode 100644 rbx_binary/benches/deserializer.rs rename rbx_binary/{bench-files => benches/files}/deep-folders-100.rbxm (100%) rename rbx_binary/{bench-files => benches/files}/folders-100.rbxm (100%) rename rbx_binary/{bench-files => benches/files}/modulescripts-100-lines-100.rbxm (100%) create mode 100644 rbx_binary/benches/files/parts-1000.rbxm delete mode 100644 rbx_binary/benches/serializer.rs create mode 100644 rbx_binary/benches/suite/main.rs create mode 100644 rbx_binary/benches/suite/util.rs diff --git a/rbx_binary/Cargo.toml b/rbx_binary/Cargo.toml index 840fc7f34..b053bfff0 100644 --- a/rbx_binary/Cargo.toml +++ b/rbx_binary/Cargo.toml @@ -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 diff --git a/rbx_binary/bench-files/parts-10000.rbxm b/rbx_binary/bench-files/parts-10000.rbxm deleted file mode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eLlU# zGN&Ghmqr%3H$eeD4ftoc?fjq9O~T>812H;cAgs;~|9k`1Ht#z!8)$sU^6_xkfJ9Eq zedu%E2T_Nk0g7@QQLw7SvDoi-#Uve**Z?@qp*|2%+&p4Ug@A;ZiPh6u4<>Zq5YKCY z%Jrej;Ze*6o`XRpiZ-#FDzT}huS(=y`~~v(C7=>vyy=if2&%cX)gnBi_3^bbvsbc2 z=giKNo86B)3J%;_XG`_BFu~-4DF?W)q8x$jR7f?x6RjOW>4V_c&%S~Ffk=>bI1nox z`apOxj_=6Yn)+TFy}T$~S5SSH)E9-D99Q3Oqb?|wU>~|$Ej+xPD_#X{2;$ER`0tjO ty0ku#Yv=T&I(xgjLn7GPy7+%5M!nsO#B6Q`Y;B7n<9%{s>t97L{R^szpK1UA diff --git a/rbx_binary/benches/deserializer.rs b/rbx_binary/benches/deserializer.rs deleted file mode 100644 index 428bac769..000000000 --- a/rbx_binary/benches/deserializer.rs +++ /dev/null @@ -1,55 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion}; - -pub fn de_folders_100(c: &mut Criterion) { - static BUFFER: &[u8] = include_bytes!("../bench-files/folders-100.rbxm"); - - c.bench_function("Deserialize 100 Folders", |b| { - b.iter(|| { - deserialize_bench(BUFFER); - }); - }); -} - -pub fn de_deep_folders_100(c: &mut Criterion) { - static BUFFER: &[u8] = include_bytes!("../bench-files/deep-folders-100.rbxm"); - - c.bench_function("Deserialize 100 deeply nested Folders", |b| { - b.iter(|| { - deserialize_bench(BUFFER); - }); - }); -} - -pub fn de_modulescripts_100_lines_100(c: &mut Criterion) { - static BUFFER: &[u8] = include_bytes!("../bench-files/modulescripts-100-lines-100.rbxm"); - - c.bench_function("Deserialize 100 100-line ModuleScripts", |b| { - b.iter(|| { - deserialize_bench(BUFFER); - }); - }); -} - -pub fn de_parts_10000(c: &mut Criterion) { - static BUFFER: &[u8] = include_bytes!("../bench-files/parts-10000.rbxm"); - - c.bench_function("Deserialize 10,000 Parts", |b| { - b.iter(|| { - deserialize_bench(BUFFER); - }); - }); -} - -#[inline(always)] -fn deserialize_bench(buffer: &[u8]) { - rbx_binary::from_reader(buffer).unwrap(); -} - -criterion_group!( - deserializer, - de_folders_100, - de_deep_folders_100, - de_modulescripts_100_lines_100, - de_parts_10000 -); -criterion_main!(deserializer); diff --git a/rbx_binary/bench-files/deep-folders-100.rbxm b/rbx_binary/benches/files/deep-folders-100.rbxm similarity index 100% rename from rbx_binary/bench-files/deep-folders-100.rbxm rename to rbx_binary/benches/files/deep-folders-100.rbxm diff --git a/rbx_binary/bench-files/folders-100.rbxm b/rbx_binary/benches/files/folders-100.rbxm similarity index 100% rename from rbx_binary/bench-files/folders-100.rbxm rename to rbx_binary/benches/files/folders-100.rbxm diff --git a/rbx_binary/bench-files/modulescripts-100-lines-100.rbxm b/rbx_binary/benches/files/modulescripts-100-lines-100.rbxm similarity index 100% rename from rbx_binary/bench-files/modulescripts-100-lines-100.rbxm rename to rbx_binary/benches/files/modulescripts-100-lines-100.rbxm diff --git a/rbx_binary/benches/files/parts-1000.rbxm b/rbx_binary/benches/files/parts-1000.rbxm new file mode 100644 index 0000000000000000000000000000000000000000..3ef7f4e33db10f512f2bffb8e76817212e317e4a GIT binary patch literal 4261 zcmb_gOK%%h6dpTn^Nvd^0c{0N5DO5304-3YKPkI^Vg>6mMtL@`o#*2919y@h-%A71R?8o!tE%uEgO^>G z%Z2($^-|Mvn2)cj^b}A z@6u$p$XwUruAAQakuXuy6}1YBOsaM%vB!lQ^-l4NQHuCaF(1tk#CJi!Zw;ed(EEfC ztBm?CTUN)lbJTp*r+RM>&pW(QKQ*QL$K9(rvf8v(}NxXfm2)W8FLBCNpCeqOWf%T9?b1_e-tKn82 zby8iuy4n-=!h0p%?><1F9|iUEZJ6`u=f`^23jF;^px2>(jW#_RHPJfAhVfWWkUp{| zn`6m}?3~#u5y_Bqw)FuB$`q;lWw?$JtOGYO!vD^in!{|j#T;%M8@-G01^VEvFl!}A;Q4i m>(hf_lmEkJF;vG3|A*zz3Me@RgvNPh+W&Ln+5Z48Qxi}C literal 0 HcmV?d00001 diff --git a/rbx_binary/benches/serializer.rs b/rbx_binary/benches/serializer.rs deleted file mode 100644 index 367517fd8..000000000 --- a/rbx_binary/benches/serializer.rs +++ /dev/null @@ -1,48 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion}; - -use rbx_dom_weak::{InstanceBuilder, WeakDom}; - -pub fn ser_folders_100(c: &mut Criterion) { - let mut tree = WeakDom::new(InstanceBuilder::new("Folder").with_name("Container")); - let root_ref = tree.root_ref(); - - for i in 0..99 { - tree.insert( - root_ref, - InstanceBuilder::new("Folder").with_name(format!("Folder {}", i)), - ); - } - - let mut buffer = Vec::new(); - - // Encode once into the buffer to pre-size it. - rbx_binary::to_writer(&mut buffer, &tree, &[root_ref]).unwrap(); - buffer.clear(); - - c.bench_function("Serialize 100 Folders", |b| { - b.iter(|| { - rbx_binary::to_writer(&mut buffer, &tree, &[root_ref]).unwrap(); - buffer.clear(); - }); - }); -} - -pub fn ser_parts_10000(c: &mut Criterion) { - static BUFFER: &[u8] = include_bytes!("../bench-files/parts-10000.rbxm"); - 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(); - buffer.clear(); - - c.bench_function("Serialize 10,000 Parts", |b| { - b.iter(|| { - rbx_binary::to_writer(&mut buffer, &tree, &[root_ref]).unwrap(); - buffer.clear(); - }) - }); -} - -criterion_group!(serializer, ser_folders_100, ser_parts_10000); -criterion_main!(serializer); diff --git a/rbx_binary/benches/suite/main.rs b/rbx_binary/benches/suite/main.rs new file mode 100644 index 000000000..a1e88e0de --- /dev/null +++ b/rbx_binary/benches/suite/main.rs @@ -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); diff --git a/rbx_binary/benches/suite/util.rs b/rbx_binary/benches/suite/util.rs new file mode 100644 index 000000000..8e835132d --- /dev/null +++ b/rbx_binary/benches/suite/util.rs @@ -0,0 +1,37 @@ +use criterion::{measurement::Measurement, BatchSize, BenchmarkGroup, Throughput}; + +pub(crate) fn bench(group: &mut BenchmarkGroup, bench_file: &'static [u8]) { + serialize_bench(group, bench_file); + deserialize_bench(group, bench_file); +} + +fn serialize_bench(group: &mut BenchmarkGroup, 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| { + rbx_binary::to_writer(&mut buffer, &tree, &[root_ref]).unwrap(); + }, + BatchSize::SmallInput, + ) + }); +} + +fn deserialize_bench(group: &mut BenchmarkGroup, buffer: &[u8]) { + group + .throughput(Throughput::Bytes(buffer.len() as u64)) + .bench_function("Deserialize", |bencher| { + bencher.iter(|| { + rbx_binary::from_reader(buffer).unwrap(); + }); + }); +}