1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

maybe optimization

This commit is contained in:
mat 2022-04-22 20:49:42 -05:00
parent b03d3da659
commit 3057ae8b4a
2 changed files with 17 additions and 15 deletions

View file

@ -25,24 +25,23 @@ fn bench_serialize(filename: &str, c: &mut Criterion) {
.block_on(async { Tag::read(&mut decoded_src_stream).await.unwrap() });
let mut group = c.benchmark_group(filename);
group.sample_size(1000);
group.throughput(Throughput::Bytes(decoded_src.len() as u64));
group.bench_function("Decode", |b| {
b.to_async(tokio::runtime::Runtime::new().unwrap())
.iter(|| async {
let mut owned_decoded_src_stream = decoded_src_stream.clone();
owned_decoded_src_stream.seek(SeekFrom::Start(0)).unwrap();
Tag::read(&mut owned_decoded_src_stream).await.unwrap();
})
});
// group.bench_function("Encode", |b| {
// b.iter(|| {
// nbt.write(&mut io::sink()).unwrap();
// })
// group.bench_function("Decode", |b| {
// b.to_async(tokio::runtime::Runtime::new().unwrap())
// .iter(|| async {
// let mut owned_decoded_src_stream = decoded_src_stream.clone();
// owned_decoded_src_stream.seek(SeekFrom::Start(0)).unwrap();
// Tag::read(&mut owned_decoded_src_stream).await.unwrap();
// })
// });
group.bench_function("Encode", |b| {
b.iter(|| {
nbt.write(&mut io::sink()).unwrap();
})
});
group.finish();
}

View file

@ -54,6 +54,7 @@ impl Tag {
match first_tag {
Self::Int(_) => {
for i in value {
assert!(matches!(i, Tag::Int(_)));
writer.write_i32::<BE>(
*i.as_int().expect("List of Int should only contains Int"),
)?;
@ -61,6 +62,7 @@ impl Tag {
}
Self::String(_) => {
for i in value {
assert!(matches!(i, Tag::String(_)));
write_string(
writer,
i.as_string()
@ -68,8 +70,9 @@ impl Tag {
)?;
}
}
&Self::Compound(_) => {
Self::Compound(_) => {
for i in value {
assert!(matches!(i, Tag::Compound(_)));
write_compound(
writer,
i.as_compound()