-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade criterion to 0.5.1, reorganize benchmarks
- Loading branch information
1 parent
72e772b
commit 91c6e2d
Showing
10 changed files
with
81 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T: Measurement>(group: &mut BenchmarkGroup<T>, 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<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.bench_function("Deserialize", |bencher| { | ||
bencher.iter(|| { | ||
rbx_binary::from_reader(buffer).unwrap(); | ||
}); | ||
}); | ||
} |