Skip to content

Commit

Permalink
Take BenchmarkGroup in bench fn so group can be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethloeffler committed Oct 31, 2024
1 parent e5bb471 commit ad568ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
17 changes: 9 additions & 8 deletions rbx_binary/benches/suite/main.rs
Original file line number Diff line number Diff line change
@@ -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!(
Expand Down
11 changes: 4 additions & 7 deletions rbx_binary/benches/suite/util.rs
Original file line number Diff line number Diff line change
@@ -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<T: Measurement>(group: &mut BenchmarkGroup<T>, 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<T: Measurement>(group: &mut BenchmarkGroup<T>, tree: &WeakDom) {
Expand Down

0 comments on commit ad568ef

Please sign in to comment.