use criterion::{criterion_group, criterion_main, Criterion}; use nbtea::{root_tag_from_slice, root_tag_from_slice_gzip, root_tag_to_writer}; use std::io::sink; fn encode(c: &mut Criterion) { { const DATA: &[u8] = include_bytes!("../samples/big1.nbt"); let blob = root_tag_from_slice_gzip(DATA).unwrap(); c.bench_function("big1.nbt/Decode blob", |b| { b.iter(|| root_tag_from_slice_gzip(DATA).unwrap()); }); c.bench_function("big1.nbt/Encode blob", |b| { b.iter(|| root_tag_to_writer("", &blob.tag, sink()).unwrap()); }); } { const DATA: &[u8] = include_bytes!("../samples/level.dat"); let blob = root_tag_from_slice_gzip(DATA).unwrap(); c.bench_function("level.dat/Decode blob", |b| { b.iter(|| root_tag_from_slice_gzip(DATA).unwrap()); }); c.bench_function("level.dat/Encode blob", |b| { b.iter(|| root_tag_to_writer("", &blob.tag, sink()).unwrap()); }); } { const DATA: &[u8] = include_bytes!("../samples/arrays.nbt"); let blob = root_tag_from_slice(DATA).unwrap(); c.bench_function("arrays.nbt/Decode blob", |b| { b.iter(|| root_tag_from_slice(DATA).unwrap()); }); c.bench_function("arrays.nbt/Encode blob", |b| { b.iter(|| root_tag_to_writer("", &blob.tag, sink()).unwrap()); }); } { const DATA: &[u8] = include_bytes!("../samples/complex_player.dat"); let blob = root_tag_from_slice_gzip(DATA).unwrap(); c.bench_function("complex_player.dat/Decode blob", |b| { b.iter(|| root_tag_from_slice_gzip(DATA).unwrap()); }); c.bench_function("complex_player.dat/Encode blob", |b| { b.iter(|| root_tag_to_writer("", &blob.tag, sink()).unwrap()); }); } } criterion_group!(benches, encode); criterion_main!(benches);