Avoid expensive setup

This commit is contained in:
Tony Garnock-Jones 2020-06-17 11:01:31 +02:00
parent b1c7fe8c04
commit 24afca5d32
1 changed files with 33 additions and 28 deletions

View File

@ -80,41 +80,46 @@ pub fn bench_ser_encoder(c: &mut Criterion) {
}
pub fn large_testdata_decoder_with_ann(c: &mut Criterion) {
let mut fh = std::fs::File::open("benches/testdata.bin").unwrap();
let mut bs = vec![];
fh.read_to_end(&mut bs).ok();
c.bench_function("decode testdata.bin with annotations", |b| b.iter(|| {
let mut r = reader::from_bytes(&bs[..]);
while let Some(_) = r.next(true).unwrap() {}
}));
c.bench_function("decode testdata.bin with annotations", |b| {
let mut fh = std::fs::File::open("benches/testdata.bin").unwrap();
let mut bs = vec![];
fh.read_to_end(&mut bs).ok();
b.iter(|| {
let mut r = reader::from_bytes(&bs[..]);
while let Some(_) = r.next(true).unwrap() {}
})
});
}
pub fn large_testdata_decoder_without_ann(c: &mut Criterion) {
let mut fh = std::fs::File::open("benches/testdata.bin").unwrap();
let mut bs = vec![];
fh.read_to_end(&mut bs).ok();
c.bench_function("decode testdata.bin without annotations", |b| b.iter(|| {
let mut r = reader::from_bytes(&bs[..]);
while let Some(_) = r.next(false).unwrap() {}
}));
c.bench_function("decode testdata.bin without annotations", |b| {
let mut fh = std::fs::File::open("benches/testdata.bin").unwrap();
let mut bs = vec![];
fh.read_to_end(&mut bs).ok();
b.iter(|| {
let mut r = reader::from_bytes(&bs[..]);
while let Some(_) = r.next(false).unwrap() {}
})
});
}
pub fn large_testdata_encoder(c: &mut Criterion) {
let mut fh = std::fs::File::open("benches/testdata.bin").unwrap();
let mut vs = vec![];
let mut r = reader::from_read(&mut fh);
while let Some(v) = r.next(true).unwrap() {
vs.push(v);
}
c.bench_function("encode testdata.bin", |b| b.iter_with_large_drop(|| {
let mut bs = vec![];
let mut e = encoder::Encoder::new(&mut bs);
for v in &vs {
e.write(&v).unwrap();
c.bench_function("encode testdata.bin", |b| {
let mut fh = BufReader::new(std::fs::File::open("benches/testdata.bin").unwrap());
let mut vs = vec![];
let mut r = reader::from_read(&mut fh);
while let Some(v) = r.next(true).unwrap() {
vs.push(v);
}
bs
}));
b.iter_with_large_drop(|| {
let mut bs = vec![];
let mut e = encoder::Encoder::new(&mut bs);
for v in &vs {
e.write(&v).unwrap();
}
bs
})
});
}
criterion_group!(codec,