-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Switched to
Vec
+ created benchmarks
- Loading branch information
Showing
6 changed files
with
84 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; | ||
use crab_nbt::Nbt; | ||
use std::fs::File; | ||
use std::io::Read; | ||
use bytes::{Bytes, BytesMut}; | ||
use flate2::read::GzDecoder; | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
let mut file = File::open("tests/data/complex_player.dat").expect("Failed to open file"); | ||
let mut buffer = Vec::new(); | ||
file.read_to_end(&mut buffer).expect("Failed to read file"); | ||
let mut src = &buffer[..]; | ||
|
||
let mut src_decoder = GzDecoder::new(&mut src); | ||
let mut input = Vec::new(); | ||
if src_decoder.read_to_end(&mut input).is_err() { | ||
input = buffer; | ||
} | ||
|
||
let bytes = Bytes::from_iter(input); | ||
let bytes_mut = BytesMut::from(bytes); | ||
|
||
let mut group = c.benchmark_group("read"); | ||
group.throughput(Throughput::Bytes(bytes_mut.len() as u64)); | ||
|
||
group.bench_function("read_bigtest_nbt", |b| { | ||
b.iter(|| { | ||
let output = Nbt::read(&mut bytes_mut.clone()).expect("Failed to parse NBT"); | ||
black_box(output) | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.