From 91c6e2d42eebd5870e8867147bcc2d93d5225330 Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Thu, 31 Oct 2024 09:38:21 +0000 Subject: [PATCH 1/5] Upgrade criterion to 0.5.1, reorganize benchmarks --- 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 | 42 +++++++++++++ rbx_binary/benches/suite/util.rs | 37 ++++++++++++ 10 files changed, 81 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 100644 index 302791a18154c11233e8c54544fadf01e1faf3a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13406 zcmeHOO>7%Q6ka=So94f*1hiGXNrO}gAw{ShdWaCtk5N$LY;8B9fdiBExL$R$W9`n; z28q8T5*#8FB&13pP>&orQA9!uRSz7HdPL&F9U~+z9L#&0-Sq}L>DYC&nUIlY*B;N# z&NuJ9neV+BPugtRWVgmXtPl2`=~I-Xq9`XWz{OAVv&GD_@cF#|y>==ApH4!ay;U_0 z-QXFQvsam6aVG_(+;-_)u24J;pPz<|sn(0vqmZ-AEKys*CNN>eyKuj9+xx226Zi`@ zqY;}cBNw1%J&yE=niPI>T1#Tm@(UUc(kNt1wG((f1v$gHZ7jQ-It6MQ#5CTf-T>ee zD*S#9D?+Lb;dKD=G^vth!!)=-oiQxL)VeypV1||ri#pM#l3w*@A>i2N$O=s~q=D^@ zLU9^0rrI!G2O$@jYwI-QIF!$o&SEK~1lGs5dida8LzVG_RwUP*5ZMeAj`@mI@4;f! zf{dkCm`zJbaml7Ncy0^+k8pp(*Ol4;wzhjE@o0{qwr*|*RR|2=2!aALRHlf2 z1B`&IWK!=6tKzsSKCFTrT~fg&1?#4@1SV9F4S=u8}v!Z)|XfY5}FA55mnJq!ZZAWWrs*Q;*g$XCR`vBl|A5zUTCgeujAbIBW zlte4iIatwu`v=9N_>>IU!gLl^BRV2ZjP_tP5}fP~tL^a!ywg}svY;B{0nZER%QUg3 znQ0m&n(T-_v}TXc>J^vTt6grh$XvbBS({5>CF_@bQwf)zC=(ys=fq%-HRZ{g|Kjm_ z=I}y=l-SMAj_sUI5Nq;l5G0 zzc5d@x5v``=w&;B@bTdZS8y&?8y?O>K(y@7#eW`0?t=R_0is0$dq);83@R_f22yEE zqIl9Z!18h6BzrtH1;D&*DExqXeZ7Z%m7u~jRr^fyMi3eHc?jJ79t7?}hd?vlVtk=o zhHbpV=v~wB{SONw(Yw|Qah{e&Z(tse9wC*AM#%DvFH)1i*`?K?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..668db3fea --- /dev/null +++ b/rbx_binary/benches/suite/main.rs @@ -0,0 +1,42 @@ +mod util; + +use crate::util::bench; +use criterion::{criterion_group, criterion_main, Criterion}; + +pub fn folders_100(c: &mut Criterion) { + bench( + c, + "100 Folders", + include_bytes!("../files/folders-100.rbxm"), + ) +} + +pub fn deep_folders_100(c: &mut Criterion) { + bench( + c, + "100 Deep Folders", + include_bytes!("../files/deep-folders-100.rbxm"), + ) +} + +pub fn modulescripts_100_lines_100(c: &mut Criterion) { + bench( + c, + "100 100-line ModuleScripts", + include_bytes!("../files/modulescripts-100-lines-100.rbxm"), + ) +} + +pub fn parts_1000(c: &mut Criterion) { + bench(c, "1,000 Parts", 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..ea072ab80 --- /dev/null +++ b/rbx_binary/benches/suite/util.rs @@ -0,0 +1,37 @@ +use criterion::{measurement::Measurement, BatchSize, BenchmarkGroup, Criterion}; +use rbx_dom_weak::WeakDom; + +pub(crate) fn bench(c: &mut Criterion, name: &str, bench_file: &'static [u8]) { + let mut group = c.benchmark_group(name); + let tree = rbx_binary::from_reader(bench_file).unwrap(); + + serialize_bench(&mut group, &tree); + deserialize_bench(&mut group, bench_file); + group.finish(); +} + +fn serialize_bench(group: &mut BenchmarkGroup, tree: &WeakDom) { + 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.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.bench_function("Deserialize", |bencher| { + bencher.iter(|| { + rbx_binary::from_reader(buffer).unwrap(); + }); + }); +} From e5bb471dc8bb3f011bd7188e4ff53a969106cb0d Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Thu, 31 Oct 2024 11:17:03 +0000 Subject: [PATCH 2/5] Fix clippy lints --- rbx_binary/benches/suite/util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rbx_binary/benches/suite/util.rs b/rbx_binary/benches/suite/util.rs index ea072ab80..73f93c17e 100644 --- a/rbx_binary/benches/suite/util.rs +++ b/rbx_binary/benches/suite/util.rs @@ -14,14 +14,14 @@ fn serialize_bench(group: &mut BenchmarkGroup, tree: &WeakDom let root_ref = tree.root_ref(); let mut buffer = Vec::new(); - rbx_binary::to_writer(&mut buffer, &tree, &[root_ref]).unwrap(); + rbx_binary::to_writer(&mut buffer, tree, &[root_ref]).unwrap(); let buffer_len = buffer.len(); group.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(); + rbx_binary::to_writer(&mut buffer, tree, &[root_ref]).unwrap(); }, BatchSize::SmallInput, ) From ad568efad6dc34c0ef7d1d7fabb98bcea6fdee60 Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Thu, 31 Oct 2024 11:28:32 +0000 Subject: [PATCH 3/5] Take BenchmarkGroup in bench fn so group can be configured --- rbx_binary/benches/suite/main.rs | 17 +++++++++-------- rbx_binary/benches/suite/util.rs | 11 ++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/rbx_binary/benches/suite/main.rs b/rbx_binary/benches/suite/main.rs index 668db3fea..a1e88e0de 100644 --- a/rbx_binary/benches/suite/main.rs +++ b/rbx_binary/benches/suite/main.rs @@ -1,34 +1,35 @@ mod util; use crate::util::bench; -use criterion::{criterion_group, criterion_main, Criterion}; +use criterion::{criterion_group, criterion_main, Criterion, SamplingMode}; pub fn folders_100(c: &mut Criterion) { bench( - c, - "100 Folders", + &mut c.benchmark_group("100 Folders"), include_bytes!("../files/folders-100.rbxm"), ) } pub fn deep_folders_100(c: &mut Criterion) { bench( - c, - "100 Deep Folders", + &mut c.benchmark_group("100 Deep Folders"), include_bytes!("../files/deep-folders-100.rbxm"), ) } pub fn modulescripts_100_lines_100(c: &mut Criterion) { bench( - c, - "100 100-line ModuleScripts", + &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, "1,000 Parts", include_bytes!("../files/parts-1000.rbxm")) + bench( + c.benchmark_group("1,000 Parts") + .sampling_mode(SamplingMode::Flat), + include_bytes!("../files/parts-1000.rbxm"), + ) } criterion_group!( diff --git a/rbx_binary/benches/suite/util.rs b/rbx_binary/benches/suite/util.rs index 73f93c17e..c0a8e3d47 100644 --- a/rbx_binary/benches/suite/util.rs +++ b/rbx_binary/benches/suite/util.rs @@ -1,13 +1,10 @@ -use criterion::{measurement::Measurement, BatchSize, BenchmarkGroup, Criterion}; +use criterion::{measurement::Measurement, BatchSize, BenchmarkGroup}; use rbx_dom_weak::WeakDom; -pub(crate) fn bench(c: &mut Criterion, name: &str, bench_file: &'static [u8]) { - let mut group = c.benchmark_group(name); +pub(crate) fn bench(group: &mut BenchmarkGroup, bench_file: &'static [u8]) { let tree = rbx_binary::from_reader(bench_file).unwrap(); - - serialize_bench(&mut group, &tree); - deserialize_bench(&mut group, bench_file); - group.finish(); + serialize_bench(group, &tree); + deserialize_bench(group, bench_file); } fn serialize_bench(group: &mut BenchmarkGroup, tree: &WeakDom) { From ddc847aeee76317649d9e6c94d1ee6756a831e78 Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Thu, 31 Oct 2024 12:52:17 +0000 Subject: [PATCH 4/5] Measure throughput too --- rbx_binary/benches/suite/main.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/rbx_binary/benches/suite/main.rs b/rbx_binary/benches/suite/main.rs index a1e88e0de..391c667dd 100644 --- a/rbx_binary/benches/suite/main.rs +++ b/rbx_binary/benches/suite/main.rs @@ -1,34 +1,42 @@ mod util; use crate::util::bench; -use criterion::{criterion_group, criterion_main, Criterion, SamplingMode}; +use criterion::{criterion_group, criterion_main, Criterion, SamplingMode, Throughput}; pub fn folders_100(c: &mut Criterion) { + let bytes = include_bytes!("../files/folders-100.rbxm"); bench( - &mut c.benchmark_group("100 Folders"), - include_bytes!("../files/folders-100.rbxm"), + c.benchmark_group("100 Folders") + .throughput(Throughput::Bytes(bytes.len() as u64)), + bytes, ) } pub fn deep_folders_100(c: &mut Criterion) { + let bytes = include_bytes!("../files/deep-folders-100.rbxm"); bench( - &mut c.benchmark_group("100 Deep Folders"), - include_bytes!("../files/deep-folders-100.rbxm"), + c.benchmark_group("100 Deep Folders") + .throughput(Throughput::Bytes(bytes.len() as u64)), + bytes, ) } pub fn modulescripts_100_lines_100(c: &mut Criterion) { + let bytes = include_bytes!("../files/modulescripts-100-lines-100.rbxm"); bench( - &mut c.benchmark_group("100 100-line ModuleScripts"), - include_bytes!("../files/modulescripts-100-lines-100.rbxm"), + c.benchmark_group("100 100-line ModuleScripts") + .throughput(Throughput::Bytes(bytes.len() as u64)), + bytes, ) } pub fn parts_1000(c: &mut Criterion) { + let bytes = include_bytes!("../files/parts-1000.rbxm"); bench( c.benchmark_group("1,000 Parts") - .sampling_mode(SamplingMode::Flat), - include_bytes!("../files/parts-1000.rbxm"), + .sampling_mode(SamplingMode::Flat) + .throughput(Throughput::Bytes(bytes.len() as u64)), + bytes, ) } From 1261e9b4c3744082e2ae1c496158a7bba16b3920 Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Thu, 31 Oct 2024 15:07:47 +0000 Subject: [PATCH 5/5] Move throughput calls to utils Serialization would not be accurate before, because the serialized size will not necessarily the same as the input file --- rbx_binary/benches/suite/main.rs | 26 +++++++------------- rbx_binary/benches/suite/util.rs | 41 +++++++++++++++++--------------- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/rbx_binary/benches/suite/main.rs b/rbx_binary/benches/suite/main.rs index 391c667dd..a1e88e0de 100644 --- a/rbx_binary/benches/suite/main.rs +++ b/rbx_binary/benches/suite/main.rs @@ -1,42 +1,34 @@ mod util; use crate::util::bench; -use criterion::{criterion_group, criterion_main, Criterion, SamplingMode, Throughput}; +use criterion::{criterion_group, criterion_main, Criterion, SamplingMode}; pub fn folders_100(c: &mut Criterion) { - let bytes = include_bytes!("../files/folders-100.rbxm"); bench( - c.benchmark_group("100 Folders") - .throughput(Throughput::Bytes(bytes.len() as u64)), - bytes, + &mut c.benchmark_group("100 Folders"), + include_bytes!("../files/folders-100.rbxm"), ) } pub fn deep_folders_100(c: &mut Criterion) { - let bytes = include_bytes!("../files/deep-folders-100.rbxm"); bench( - c.benchmark_group("100 Deep Folders") - .throughput(Throughput::Bytes(bytes.len() as u64)), - bytes, + &mut c.benchmark_group("100 Deep Folders"), + include_bytes!("../files/deep-folders-100.rbxm"), ) } pub fn modulescripts_100_lines_100(c: &mut Criterion) { - let bytes = include_bytes!("../files/modulescripts-100-lines-100.rbxm"); bench( - c.benchmark_group("100 100-line ModuleScripts") - .throughput(Throughput::Bytes(bytes.len() as u64)), - bytes, + &mut c.benchmark_group("100 100-line ModuleScripts"), + include_bytes!("../files/modulescripts-100-lines-100.rbxm"), ) } pub fn parts_1000(c: &mut Criterion) { - let bytes = include_bytes!("../files/parts-1000.rbxm"); bench( c.benchmark_group("1,000 Parts") - .sampling_mode(SamplingMode::Flat) - .throughput(Throughput::Bytes(bytes.len() as u64)), - bytes, + .sampling_mode(SamplingMode::Flat), + include_bytes!("../files/parts-1000.rbxm"), ) } diff --git a/rbx_binary/benches/suite/util.rs b/rbx_binary/benches/suite/util.rs index c0a8e3d47..8e835132d 100644 --- a/rbx_binary/benches/suite/util.rs +++ b/rbx_binary/benches/suite/util.rs @@ -1,34 +1,37 @@ -use criterion::{measurement::Measurement, BatchSize, BenchmarkGroup}; -use rbx_dom_weak::WeakDom; +use criterion::{measurement::Measurement, BatchSize, BenchmarkGroup, Throughput}; pub(crate) fn bench(group: &mut BenchmarkGroup, bench_file: &'static [u8]) { - let tree = rbx_binary::from_reader(bench_file).unwrap(); - serialize_bench(group, &tree); + serialize_bench(group, bench_file); deserialize_bench(group, bench_file); } -fn serialize_bench(group: &mut BenchmarkGroup, tree: &WeakDom) { +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(); + rbx_binary::to_writer(&mut buffer, &tree, &[root_ref]).unwrap(); let buffer_len = buffer.len(); - group.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, - ) - }); + 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.bench_function("Deserialize", |bencher| { - bencher.iter(|| { - rbx_binary::from_reader(buffer).unwrap(); + group + .throughput(Throughput::Bytes(buffer.len() as u64)) + .bench_function("Deserialize", |bencher| { + bencher.iter(|| { + rbx_binary::from_reader(buffer).unwrap(); + }); }); - }); }