Benches
This commit is contained in:
parent
bf85504233
commit
7a71f72491
|
@ -14,5 +14,12 @@ num-bigint = "0.4"
|
|||
num-traits = "0.2"
|
||||
regex = "1.5"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
|
||||
[[bench]]
|
||||
name = "codec"
|
||||
harness = false
|
||||
|
||||
[package.metadata.workspaces]
|
||||
independent = true
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
testdata.bin
|
|
@ -0,0 +1,98 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use oo::BinarySource;
|
||||
use oo::BytesBinarySource;
|
||||
use oo::IOBinarySource;
|
||||
use oo::IOValueDomainCodec;
|
||||
use oo::IOValues;
|
||||
use oo::PackedWriter;
|
||||
use oo::Reader;
|
||||
use oo::Value;
|
||||
use oo::packed::annotated_iovalue_from_bytes;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::io::Seek;
|
||||
use std::io;
|
||||
|
||||
pub fn bench_decoder_bytes(c: &mut Criterion) {
|
||||
let mut fh = File::open("../../../tests/samples.bin").unwrap();
|
||||
let mut bs = vec![];
|
||||
fh.read_to_end(&mut bs).ok();
|
||||
c.bench_function("(oo) decode samples.bin via bytes", |b| b.iter_with_large_drop(
|
||||
|| annotated_iovalue_from_bytes(&bs[..]).unwrap()));
|
||||
}
|
||||
|
||||
pub fn bench_decoder_file(c: &mut Criterion) {
|
||||
let mut fh = File::open("../../../tests/samples.bin").unwrap();
|
||||
c.bench_function("(oo) decode samples.bin via file", |b| b.iter_with_large_drop(|| {
|
||||
fh.seek(io::SeekFrom::Start(0)).ok();
|
||||
IOBinarySource::new(&mut fh).packed().next_iovalue(true).unwrap()
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn bench_decoder_buffered_file(c: &mut Criterion) {
|
||||
let mut fh = io::BufReader::new(File::open("../../../tests/samples.bin").unwrap());
|
||||
c.bench_function("(oo) decode samples.bin via buffered file", |b| b.iter_with_large_drop(|| {
|
||||
fh.seek(io::SeekFrom::Start(0)).ok();
|
||||
IOBinarySource::new(&mut fh).packed().next_iovalue(true).unwrap()
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn bench_encoder(c: &mut Criterion) {
|
||||
let mut fh = File::open("../../../tests/samples.bin").unwrap();
|
||||
let v = IOBinarySource::new(&mut fh).packed().next_iovalue(true).unwrap();
|
||||
c.bench_function("(oo) encode samples.bin", |b| b.iter_with_large_drop(
|
||||
|| PackedWriter::encode_iovalue(&v).unwrap()));
|
||||
}
|
||||
|
||||
pub fn large_testdata_decoder_with_ann(c: &mut Criterion) {
|
||||
c.bench_function("(oo) decode testdata.bin with annotations", |b| {
|
||||
let mut fh = File::open("benches/testdata.bin").unwrap();
|
||||
let mut bs = vec![];
|
||||
fh.read_to_end(&mut bs).ok();
|
||||
b.iter(|| {
|
||||
let mut src = BytesBinarySource::new(&bs[..]);
|
||||
let mut r = IOValues::new(src.packed()).read_annotations(true);
|
||||
while let Some(Ok(_)) = r.next() {}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
pub fn large_testdata_decoder_without_ann(c: &mut Criterion) {
|
||||
c.bench_function("(oo) decode testdata.bin without annotations", |b| {
|
||||
let mut fh = File::open("benches/testdata.bin").unwrap();
|
||||
let mut bs = vec![];
|
||||
fh.read_to_end(&mut bs).ok();
|
||||
b.iter(|| {
|
||||
let mut src = BytesBinarySource::new(&bs[..]);
|
||||
let mut r = IOValues::new(src.packed()).read_annotations(false);
|
||||
while let Some(Ok(_)) = r.next() {}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
pub fn large_testdata_encoder(c: &mut Criterion) {
|
||||
c.bench_function("(oo) encode testdata.bin", |b| {
|
||||
let mut fh = io::BufReader::new(File::open("benches/testdata.bin").unwrap());
|
||||
let mut src = IOBinarySource::new(&mut fh);
|
||||
let vs = IOValues::new(src.packed()).read_annotations(true).collect::<Result<Vec<_>, _>>().unwrap();
|
||||
b.iter_with_large_drop(|| {
|
||||
let mut bs = vec![];
|
||||
let mut w = PackedWriter::new(&mut bs);
|
||||
let mut enc = IOValueDomainCodec;
|
||||
for v in &vs {
|
||||
v.write(&mut w, &mut enc).unwrap();
|
||||
}
|
||||
bs
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(codec,
|
||||
bench_decoder_bytes, bench_decoder_file, bench_decoder_buffered_file,
|
||||
bench_encoder);
|
||||
criterion_group!{
|
||||
name = large_testdata;
|
||||
config = Criterion::default().sample_size(10);
|
||||
targets = large_testdata_decoder_with_ann, large_testdata_decoder_without_ann, large_testdata_encoder
|
||||
}
|
||||
criterion_main!(codec, large_testdata);
|
Binary file not shown.
|
@ -19,6 +19,7 @@ pub use packed::annotated_from_bytes;
|
|||
pub use packed::annotated_iovalue_from_bytes;
|
||||
pub use packed::from_bytes;
|
||||
pub use packed::iovalue_from_bytes;
|
||||
pub use reader::IOValues;
|
||||
pub use reader::Reader;
|
||||
pub use repr::Annotations;
|
||||
pub use repr::ArcValue;
|
||||
|
|
Loading…
Reference in New Issue