From 3057ae8b4ad616258f9f4fd777d85fb20a6eef9c Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 22 Apr 2022 20:49:42 -0500 Subject: maybe optimization --- azalea-nbt/benches/my_benchmark.rs | 27 +++++++++++++-------------- azalea-nbt/src/encode.rs | 5 ++++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/azalea-nbt/benches/my_benchmark.rs b/azalea-nbt/benches/my_benchmark.rs index 00d12dc8..fcb44f90 100755 --- a/azalea-nbt/benches/my_benchmark.rs +++ b/azalea-nbt/benches/my_benchmark.rs @@ -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(); } diff --git a/azalea-nbt/src/encode.rs b/azalea-nbt/src/encode.rs index ef72dce2..d1126ee0 100755 --- a/azalea-nbt/src/encode.rs +++ b/azalea-nbt/src/encode.rs @@ -54,6 +54,7 @@ impl Tag { match first_tag { Self::Int(_) => { for i in value { + assert!(matches!(i, Tag::Int(_))); writer.write_i32::( *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() -- cgit v1.2.3