aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-12-25 15:10:08 -0600
committermat <github@matdoes.dev>2021-12-25 15:10:08 -0600
commit1cdd061a999bfa16907ebcc5ab38b1863839b5f1 (patch)
treef5d164977eb9db82555e03e9fb720120ee8f0595
parent6ae94b96e6d51e3bf251d4a01f17fa7d41c9500f (diff)
downloadazalea-drasl-1cdd061a999bfa16907ebcc5ab38b1863839b5f1.tar.xz
ok i give up remove the async benchmarks
-rw-r--r--azalea-nbt/benches/my_benchmark.rs19
-rw-r--r--azalea-protocol/src/mc_buf.rs10
2 files changed, 17 insertions, 12 deletions
diff --git a/azalea-nbt/benches/my_benchmark.rs b/azalea-nbt/benches/my_benchmark.rs
index 1e642716..7b44d610 100644
--- a/azalea-nbt/benches/my_benchmark.rs
+++ b/azalea-nbt/benches/my_benchmark.rs
@@ -3,7 +3,7 @@ use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use flate2::read::GzDecoder;
use std::{
fs::File,
- io::{self, Read, Seek, SeekFrom},
+ io::{self, Cursor, Read, Seek, SeekFrom},
};
fn bench_serialize(filename: &str, c: &mut Criterion) {
@@ -25,14 +25,17 @@ 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.throughput(Throughput::Bytes(decoded_src.len() as u64));
- group.bench_function("Decode", |b| {
- b.to_async(tokio::runtime::Runtime::new().unwrap())
- .iter(|| {
- decoded_src_stream.seek(SeekFrom::Start(0)).unwrap();
- Tag::read(&mut decoded_src_stream)
- })
- });
+
+ // idk if this is criterion's fault or rust's fault but the async benchmark doesn't compile
+ // group.bench_function("Decode", |b| {
+ // b.to_async(tokio::runtime::Runtime::new().unwrap();).iter(|| async {
+ // decoded_src_stream.seek(SeekFrom::Start(0)).unwrap();
+ // Tag::read(&mut decoded_src_stream).await.unwrap();
+ // })
+ // });
+
group.bench_function("Encode", |b| {
b.iter(|| {
nbt.write(&mut io::sink()).unwrap();
diff --git a/azalea-protocol/src/mc_buf.rs b/azalea-protocol/src/mc_buf.rs
index 3959560d..cf98aca3 100644
--- a/azalea-protocol/src/mc_buf.rs
+++ b/azalea-protocol/src/mc_buf.rs
@@ -191,7 +191,7 @@ where
fn get_varint_size(&mut self, value: i32) -> u8 {
for i in 1..5 {
- if (value & -1 << i * 7) != 0 {
+ if (value & -1 << (i * 7)) != 0 {
continue;
}
return i;
@@ -201,7 +201,7 @@ where
fn get_varlong_size(&mut self, value: i32) -> u8 {
for i in 1..10 {
- if (value & -1 << i * 7) != 0 {
+ if (value & -1 << (i * 7)) != 0 {
continue;
}
return i;
@@ -285,8 +285,7 @@ where
}
async fn read_nbt(&mut self) -> Result<azalea_nbt::Tag, String> {
- self.peek();
- Ok(azalea_nbt::Tag::read(self).unwrap())
+ Ok(azalea_nbt::Tag::read(self).await.unwrap())
}
}
@@ -311,12 +310,15 @@ mod tests {
async fn test_read_varint() {
let mut buf = BufReader::new(Cursor::new(vec![192, 196, 7]));
assert_eq!(buf.read_varint().await.unwrap(), 123456);
+ assert_eq!(buf.get_varint_size(123456), 3);
let mut buf = BufReader::new(Cursor::new(vec![0]));
assert_eq!(buf.read_varint().await.unwrap(), 0);
+ assert_eq!(buf.get_varint_size(0), 1);
let mut buf = BufReader::new(Cursor::new(vec![1]));
assert_eq!(buf.read_varint().await.unwrap(), 1);
+ assert_eq!(buf.get_varint_size(1), 1);
}
#[tokio::test]