From ad568efad6dc34c0ef7d1d7fabb98bcea6fdee60 Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Thu, 31 Oct 2024 11:28:32 +0000 Subject: [PATCH] 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 668db3fe..a1e88e0d 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 73f93c17..c0a8e3d4 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) {