From 7a71f72491548649f7c2956e69714c57095aeb26 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 8 Nov 2022 21:02:07 +0100 Subject: [PATCH] Benches --- implementations/rust/oo/Cargo.toml | 7 ++ implementations/rust/oo/benches/.gitignore | 1 + implementations/rust/oo/benches/codec.rs | 98 ++++++++++++++++++ .../rust/oo/benches/testdata.bin.gz | Bin 0 -> 72659 bytes implementations/rust/oo/src/lib.rs | 1 + 5 files changed, 107 insertions(+) create mode 100644 implementations/rust/oo/benches/.gitignore create mode 100644 implementations/rust/oo/benches/codec.rs create mode 100644 implementations/rust/oo/benches/testdata.bin.gz diff --git a/implementations/rust/oo/Cargo.toml b/implementations/rust/oo/Cargo.toml index 82ce8ce..f79194e 100644 --- a/implementations/rust/oo/Cargo.toml +++ b/implementations/rust/oo/Cargo.toml @@ -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 diff --git a/implementations/rust/oo/benches/.gitignore b/implementations/rust/oo/benches/.gitignore new file mode 100644 index 0000000..800aca2 --- /dev/null +++ b/implementations/rust/oo/benches/.gitignore @@ -0,0 +1 @@ +testdata.bin diff --git a/implementations/rust/oo/benches/codec.rs b/implementations/rust/oo/benches/codec.rs new file mode 100644 index 0000000..f1055ae --- /dev/null +++ b/implementations/rust/oo/benches/codec.rs @@ -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::, _>>().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); diff --git a/implementations/rust/oo/benches/testdata.bin.gz b/implementations/rust/oo/benches/testdata.bin.gz new file mode 100644 index 0000000000000000000000000000000000000000..469262f273e693b8e5b2ce264e39e1ab0a2ca4ec GIT binary patch literal 72659 zcmeI*JuAck0LSsaC}+{#4Gb=_xjf_{CIeQbWK^#6FeqKgEn-qqB!d?~M&$+%rJPJ$ z3=B3!kr+rM%HW~fZ6@{k^?e1OH}I=k2!)33-V#A!dSoI!oJ=Ph21irD<4IHLOk>c| zTO7@nZ!Hh3#us}Iw;OjSs>k+MVz-|!_it@I-KX(PE}TeSPE}O)A0J#D^{=wfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72>dGWe3pqtgZw_eFCv@cv787HAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5;&zX|Nr&K2dq0A{`p-e*gi z*J|cPfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkL{ RUklts3bXa8uJFcm!4K!f*