1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00
azalea/azalea-nbt/benches/compare.rs
mat 634cb8d72c
Inventory (#48)
* start adding azalea-inventory

* design more of how inventories are defined

* start working on az-inv-macros

* inventory macro works

* start adding inventory codegen

* update some deps

* add inventory codegen

* manually write inventory menus

* put the inventories in Client

* start on containersetcontent

* inventory menu should hopefully work

* checks in containersetcontent

* format a comment

* move some variant matches

* inventory.rs

* inventory stuff

* more inventory stuff

* inventory/container tracking works

* start adding interact function

* sequence number

* start adding HitResultComponent

* implement traverse_blocks

* start adding clip

* add clip function

* update_hit_result_component

* start trying to fix

* fix

* make some stuff simpler

* clippy

* lever

* chest

* container handle

* fix ambiguity

* fix some doc tests

* move some container stuff from az-client to azalea

* clicking container

* start implementing simulate_click

* keep working on simulate click

* implement more of simulate_click

this is really boring

* inventory fixes

* start implementing shift clicking

* fix panic in azalea-chat i hope

* shift clicking implemented

* more inventory stuff

* fix items not showing in containers sometimes

* fix test

* fix all warnings

* remove a println

---------

Co-authored-by: mat <git@matdoes.dev>
2023-05-03 20:57:27 -05:00

91 lines
2.9 KiB
Rust
Executable file

use std::{
fs::File,
io::{Cursor, Read},
};
use azalea_buf::McBufReadable;
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
use flate2::read::GzDecoder;
pub fn bench_read_file(filename: &str, c: &mut Criterion) {
let mut file = File::open(filename).unwrap();
let mut contents = Vec::new();
file.read_to_end(&mut contents).unwrap();
let mut src = &contents[..];
// decode the original src so most of the time isn't spent on unzipping
let mut decoded_src_decoder = GzDecoder::new(&mut src);
let mut input = Vec::new();
decoded_src_decoder.read_to_end(&mut input).unwrap();
let input = input.as_slice();
let mut group = c.benchmark_group(filename);
group.throughput(Throughput::Bytes(input.len() as u64));
group.bench_function("azalea_parse", |b| {
b.iter(|| {
let input = black_box(input);
let nbt = azalea_nbt::Nbt::read(&mut Cursor::new(&input)).unwrap();
black_box(nbt);
})
});
group.bench_function("graphite_parse", |b| {
b.iter(|| {
let input = black_box(input);
let nbt = graphite_binary::nbt::decode::read(&mut &input[..]).unwrap();
black_box(nbt);
})
});
// group.bench_function("valence_parse", |b| {
// b.iter(|| {
// let input = black_box(input);
// let nbt = valence_nbt::from_binary_slice(&mut &input[..]).unwrap();
// black_box(nbt);
// })
// });
// // writing
let nbt = azalea_nbt::Nbt::read_from(&mut Cursor::new(input)).unwrap();
group.bench_function("azalea_write", |b| {
b.iter(|| {
let nbt = black_box(&nbt);
let mut written = Vec::new();
nbt.write(&mut written);
black_box(written);
})
});
let nbt = graphite_binary::nbt::decode::read(&mut &input[..]).unwrap();
group.bench_function("graphite_write", |b| {
b.iter(|| {
let nbt = black_box(&nbt);
let written = graphite_binary::nbt::encode::write(nbt);
black_box(written);
})
});
// let nbt = valence_nbt::from_binary_slice(&mut &input[..]).unwrap();
// group.bench_function("valence_write", |b| {
// b.iter(|| {
// let nbt = black_box(&nbt);
// let mut written = Vec::new();
// valence_nbt::to_binary_writer(&mut written, &nbt.0,
// &nbt.1).unwrap(); black_box(written);
// })
// });
}
fn bench(c: &mut Criterion) {
bench_read_file("tests/bigtest.nbt", c);
// bench_read_file("tests/simple_player.dat", c);
bench_read_file("tests/complex_player.dat", c);
// bench_read_file("tests/level.dat", c);
// bench_read_file("tests/stringtest.nbt", c);
// bench_read_file("tests/inttest.nbt", c);
}
criterion_group!(benches, bench);
criterion_main!(benches);