-
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.
Serialization would not be accurate before, because the serialized size will not necessarily the same as the input file
- Loading branch information
1 parent
ddc847a
commit 1261e9b
Showing
2 changed files
with
31 additions
and
36 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
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 |
---|---|---|
@@ -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<T: Measurement>(group: &mut BenchmarkGroup<T>, 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<T: Measurement>(group: &mut BenchmarkGroup<T>, tree: &WeakDom) { | ||
fn serialize_bench<T: Measurement>(group: &mut BenchmarkGroup<T>, 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<u8>| { | ||
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<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(); | ||
group | ||
.throughput(Throughput::Bytes(buffer.len() as u64)) | ||
.bench_function("Deserialize", |bencher| { | ||
bencher.iter(|| { | ||
rbx_binary::from_reader(buffer).unwrap(); | ||
}); | ||
}); | ||
}); | ||
} |