From 350bbac2828ebd5b2a5abac5c54014d271e8603a Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 22 Mar 2023 20:59:33 -0500 Subject: rename benchmarks --- azalea-nbt/Cargo.toml | 2 +- azalea-nbt/benches/compare.rs | 91 ++++++++++++++++++++++++++++++++++++++ azalea-nbt/benches/comparison.rs | 91 -------------------------------------- azalea-nbt/benches/my_benchmark.rs | 54 ---------------------- azalea-nbt/benches/nbt.rs | 54 ++++++++++++++++++++++ 5 files changed, 146 insertions(+), 146 deletions(-) create mode 100755 azalea-nbt/benches/compare.rs delete mode 100755 azalea-nbt/benches/comparison.rs delete mode 100755 azalea-nbt/benches/my_benchmark.rs create mode 100755 azalea-nbt/benches/nbt.rs diff --git a/azalea-nbt/Cargo.toml b/azalea-nbt/Cargo.toml index 4f01e254..e14c501f 100644 --- a/azalea-nbt/Cargo.toml +++ b/azalea-nbt/Cargo.toml @@ -38,4 +38,4 @@ debug = true [[bench]] harness = false -name = "my_benchmark" +name = "nbt" diff --git a/azalea-nbt/benches/compare.rs b/azalea-nbt/benches/compare.rs new file mode 100755 index 00000000..7aede267 --- /dev/null +++ b/azalea-nbt/benches/compare.rs @@ -0,0 +1,91 @@ +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::Tag::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::Tag::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).unwrap(); + // 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); diff --git a/azalea-nbt/benches/comparison.rs b/azalea-nbt/benches/comparison.rs deleted file mode 100755 index 7aede267..00000000 --- a/azalea-nbt/benches/comparison.rs +++ /dev/null @@ -1,91 +0,0 @@ -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::Tag::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::Tag::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).unwrap(); - // 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); diff --git a/azalea-nbt/benches/my_benchmark.rs b/azalea-nbt/benches/my_benchmark.rs deleted file mode 100755 index 7ce11e1f..00000000 --- a/azalea-nbt/benches/my_benchmark.rs +++ /dev/null @@ -1,54 +0,0 @@ -use azalea_nbt::Tag; -use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; -use flate2::read::GzDecoder; -use std::{ - fs::File, - io::{self, Cursor, Read}, -}; - -fn bench_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 decoded_src = Vec::new(); - decoded_src_decoder.read_to_end(&mut decoded_src).unwrap(); - - let mut decoded_src_stream = Cursor::new(&decoded_src[..]); - - let nbt = Tag::read(&mut decoded_src_stream).unwrap(); - decoded_src_stream.set_position(0); - - let mut group = c.benchmark_group(filename); - - group.throughput(Throughput::Bytes(decoded_src.len() as u64)); - - group.bench_function("Decode", |b| { - b.iter(|| { - black_box(Tag::read(&mut decoded_src_stream).unwrap()); - decoded_src_stream.set_position(0); - }) - }); - - group.bench_function("Encode", |b| { - b.iter(|| { - nbt.write(&mut io::sink()).unwrap(); - }) - }); - group.finish(); -} - -fn bench(c: &mut Criterion) { - bench_file("tests/bigtest.nbt", c); - bench_file("tests/simple_player.dat", c); - bench_file("tests/complex_player.dat", c); - bench_file("tests/level.dat", c); - bench_file("tests/stringtest.nbt", c); - bench_file("tests/inttest.nbt", c); -} - -criterion_group!(benches, bench); -criterion_main!(benches); diff --git a/azalea-nbt/benches/nbt.rs b/azalea-nbt/benches/nbt.rs new file mode 100755 index 00000000..5eeb733f --- /dev/null +++ b/azalea-nbt/benches/nbt.rs @@ -0,0 +1,54 @@ +use azalea_nbt::Tag; +use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; +use flate2::read::GzDecoder; +use std::{ + fs::File, + io::{self, Cursor, Read}, +}; + +fn bench_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 decoded_src = Vec::new(); + decoded_src_decoder.read_to_end(&mut decoded_src).unwrap(); + + let mut decoded_src_stream = Cursor::new(&decoded_src[..]); + + let nbt = Tag::read(&mut decoded_src_stream).unwrap(); + decoded_src_stream.set_position(0); + + let mut group = c.benchmark_group(filename); + + group.throughput(Throughput::Bytes(decoded_src.len() as u64)); + + // group.bench_function("Decode", |b| { + // b.iter(|| { + // black_box(Tag::read(&mut decoded_src_stream).unwrap()); + // decoded_src_stream.set_position(0); + // }) + // }); + + group.bench_function("Encode", |b| { + b.iter(|| { + nbt.write(&mut io::sink()).unwrap(); + }) + }); + group.finish(); +} + +fn bench(c: &mut Criterion) { + // bench_file("tests/bigtest.nbt", c); + // bench_file("tests/simple_player.dat", c); + bench_file("tests/complex_player.dat", c); + // bench_file("tests/level.dat", c); + // bench_file("tests/stringtest.nbt", c); + // bench_file("tests/inttest.nbt", c); +} + +criterion_group!(benches, bench); +criterion_main!(benches); -- cgit v1.2.3