Repair benchmark
This commit is contained in:
parent
cbf5a9d2ac
commit
59832ee1d5
|
@ -31,7 +31,7 @@ pub fn bench_decoder_file(c: &mut Criterion) {
|
|||
let mut fh = File::open("../../../tests/samples.bin").unwrap();
|
||||
c.bench_function("decode samples.bin via file", |b| b.iter_with_large_drop(|| {
|
||||
fh.seek(io::SeekFrom::Start(0)).ok();
|
||||
IOBinarySource::new(&mut fh).packed_iovalues().demand_next(true).unwrap()
|
||||
IOBinarySource::new(&mut fh).packed().iovalues().demand_next().unwrap()
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -39,13 +39,13 @@ pub fn bench_decoder_buffered_file(c: &mut Criterion) {
|
|||
let mut fh = io::BufReader::new(File::open("../../../tests/samples.bin").unwrap());
|
||||
c.bench_function("decode samples.bin via buffered file", |b| b.iter_with_large_drop(|| {
|
||||
fh.seek(io::SeekFrom::Start(0)).ok();
|
||||
IOBinarySource::new(&mut fh).packed_iovalues().demand_next(true).unwrap()
|
||||
IOBinarySource::new(&mut fh).packed().iovalues().demand_next().unwrap()
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn bench_encoder(c: &mut Criterion) {
|
||||
let mut fh = File::open("../../../tests/samples.bin").unwrap();
|
||||
let v = IOBinarySource::new(&mut fh).packed_iovalues().demand_next(true).unwrap();
|
||||
let v = IOBinarySource::new(&mut fh).packed().iovalues().demand_next().unwrap();
|
||||
c.bench_function("encode samples.bin", |b| b.iter_with_large_drop(
|
||||
|| PackedWriter::encode_iovalue(&v).unwrap()));
|
||||
}
|
||||
|
@ -90,8 +90,8 @@ pub fn large_testdata_decoder_with_ann(c: &mut Criterion) {
|
|||
fh.read_to_end(&mut bs).ok();
|
||||
b.iter(|| {
|
||||
let mut src = BytesBinarySource::new(&bs[..]);
|
||||
let mut r = src.packed_iovalues();
|
||||
while let Some(_) = r.next(true).unwrap() {}
|
||||
let mut r = src.packed();
|
||||
while let Some(_) = r.next_iovalue(true).unwrap() {}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
@ -103,8 +103,8 @@ pub fn large_testdata_decoder_without_ann(c: &mut Criterion) {
|
|||
fh.read_to_end(&mut bs).ok();
|
||||
b.iter(|| {
|
||||
let mut src = BytesBinarySource::new(&bs[..]);
|
||||
let mut r = src.packed_iovalues();
|
||||
while let Some(_) = r.next(false).unwrap() {}
|
||||
let mut r = src.packed();
|
||||
while let Some(_) = r.next_iovalue(false).unwrap() {}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
@ -114,8 +114,8 @@ pub fn large_testdata_encoder(c: &mut Criterion) {
|
|||
let mut fh = io::BufReader::new(File::open("benches/testdata.bin").unwrap());
|
||||
let mut vs = vec![];
|
||||
let mut src = IOBinarySource::new(&mut fh);
|
||||
let mut r = src.packed_iovalues();
|
||||
while let Some(v) = r.next(true).unwrap() {
|
||||
let mut r = src.packed();
|
||||
while let Some(v) = r.next_iovalue(true).unwrap() {
|
||||
vs.push(v);
|
||||
}
|
||||
b.iter_with_large_drop(|| {
|
||||
|
|
Binary file not shown.
|
@ -63,7 +63,11 @@ pub trait Reader<'de> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn next_iovalue(&mut self, read_annotations: bool) -> io::Result<IOValue> {
|
||||
fn next_iovalue(&mut self, read_annotations: bool) -> io::Result<Option<IOValue>> {
|
||||
self.next(read_annotations, &mut IOValueDomainCodec)
|
||||
}
|
||||
|
||||
fn demand_next_iovalue(&mut self, read_annotations: bool) -> io::Result<IOValue> {
|
||||
self.demand_next(read_annotations, &mut IOValueDomainCodec)
|
||||
}
|
||||
|
||||
|
@ -76,45 +80,45 @@ pub trait Reader<'de> {
|
|||
}
|
||||
|
||||
fn next_boolean(&mut self) -> ReaderResult<bool> {
|
||||
self.next_iovalue(false)?.value().to_boolean()
|
||||
self.demand_next_iovalue(false)?.value().to_boolean()
|
||||
}
|
||||
|
||||
fn next_float(&mut self) -> ReaderResult<Float> {
|
||||
Ok(self.next_iovalue(false)?.value().to_float()?.to_owned())
|
||||
Ok(self.demand_next_iovalue(false)?.value().to_float()?.to_owned())
|
||||
}
|
||||
|
||||
fn next_double(&mut self) -> ReaderResult<Double> {
|
||||
Ok(self.next_iovalue(false)?.value().to_double()?.to_owned())
|
||||
Ok(self.demand_next_iovalue(false)?.value().to_double()?.to_owned())
|
||||
}
|
||||
|
||||
fn next_signedinteger(&mut self) -> ReaderResult<SignedInteger> {
|
||||
Ok(self.next_iovalue(false)?.value().to_signedinteger()?.to_owned())
|
||||
Ok(self.demand_next_iovalue(false)?.value().to_signedinteger()?.to_owned())
|
||||
}
|
||||
|
||||
fn next_i8(&mut self) -> ReaderResult<i8> { self.next_iovalue(false)?.value().to_i8() }
|
||||
fn next_u8(&mut self) -> ReaderResult<u8> { self.next_iovalue(false)?.value().to_u8() }
|
||||
fn next_i16(&mut self) -> ReaderResult<i16> { self.next_iovalue(false)?.value().to_i16() }
|
||||
fn next_u16(&mut self) -> ReaderResult<u16> { self.next_iovalue(false)?.value().to_u16() }
|
||||
fn next_i32(&mut self) -> ReaderResult<i32> { self.next_iovalue(false)?.value().to_i32() }
|
||||
fn next_u32(&mut self) -> ReaderResult<u32> { self.next_iovalue(false)?.value().to_u32() }
|
||||
fn next_i64(&mut self) -> ReaderResult<i64> { self.next_iovalue(false)?.value().to_i64() }
|
||||
fn next_u64(&mut self) -> ReaderResult<u64> { self.next_iovalue(false)?.value().to_u64() }
|
||||
fn next_i128(&mut self) -> ReaderResult<i128> { self.next_iovalue(false)?.value().to_i128() }
|
||||
fn next_u128(&mut self) -> ReaderResult<u128> { self.next_iovalue(false)?.value().to_u128() }
|
||||
fn next_f32(&mut self) -> ReaderResult<f32> { self.next_iovalue(false)?.value().to_f32() }
|
||||
fn next_f64(&mut self) -> ReaderResult<f64> { self.next_iovalue(false)?.value().to_f64() }
|
||||
fn next_char(&mut self) -> ReaderResult<char> { self.next_iovalue(false)?.value().to_char() }
|
||||
fn next_i8(&mut self) -> ReaderResult<i8> { self.demand_next_iovalue(false)?.value().to_i8() }
|
||||
fn next_u8(&mut self) -> ReaderResult<u8> { self.demand_next_iovalue(false)?.value().to_u8() }
|
||||
fn next_i16(&mut self) -> ReaderResult<i16> { self.demand_next_iovalue(false)?.value().to_i16() }
|
||||
fn next_u16(&mut self) -> ReaderResult<u16> { self.demand_next_iovalue(false)?.value().to_u16() }
|
||||
fn next_i32(&mut self) -> ReaderResult<i32> { self.demand_next_iovalue(false)?.value().to_i32() }
|
||||
fn next_u32(&mut self) -> ReaderResult<u32> { self.demand_next_iovalue(false)?.value().to_u32() }
|
||||
fn next_i64(&mut self) -> ReaderResult<i64> { self.demand_next_iovalue(false)?.value().to_i64() }
|
||||
fn next_u64(&mut self) -> ReaderResult<u64> { self.demand_next_iovalue(false)?.value().to_u64() }
|
||||
fn next_i128(&mut self) -> ReaderResult<i128> { self.demand_next_iovalue(false)?.value().to_i128() }
|
||||
fn next_u128(&mut self) -> ReaderResult<u128> { self.demand_next_iovalue(false)?.value().to_u128() }
|
||||
fn next_f32(&mut self) -> ReaderResult<f32> { self.demand_next_iovalue(false)?.value().to_f32() }
|
||||
fn next_f64(&mut self) -> ReaderResult<f64> { self.demand_next_iovalue(false)?.value().to_f64() }
|
||||
fn next_char(&mut self) -> ReaderResult<char> { self.demand_next_iovalue(false)?.value().to_char() }
|
||||
|
||||
fn next_str(&mut self) -> ReaderResult<Cow<'de, str>> {
|
||||
Ok(Cow::Owned(self.next_iovalue(false)?.value().to_string()?.to_owned()))
|
||||
Ok(Cow::Owned(self.demand_next_iovalue(false)?.value().to_string()?.to_owned()))
|
||||
}
|
||||
|
||||
fn next_bytestring(&mut self) -> ReaderResult<Cow<'de, [u8]>> {
|
||||
Ok(Cow::Owned(self.next_iovalue(false)?.value().to_bytestring()?.to_owned()))
|
||||
Ok(Cow::Owned(self.demand_next_iovalue(false)?.value().to_bytestring()?.to_owned()))
|
||||
}
|
||||
|
||||
fn next_symbol(&mut self) -> ReaderResult<Cow<'de, str>> {
|
||||
Ok(Cow::Owned(self.next_iovalue(false)?.value().to_symbol()?.to_owned()))
|
||||
Ok(Cow::Owned(self.demand_next_iovalue(false)?.value().to_symbol()?.to_owned()))
|
||||
}
|
||||
|
||||
fn open_simple_record(&mut self, name: &str) -> ReaderResult<()>
|
||||
|
|
|
@ -443,7 +443,7 @@ impl<'de, 'src, S: BinarySource<'de>> Reader<'de> for TextReader<'de, 'src, S> {
|
|||
},
|
||||
b'[' => self.read_base64_binary()?,
|
||||
b'=' => {
|
||||
let bs_val = self.next_iovalue(true)?;
|
||||
let bs_val = self.demand_next_iovalue(true)?;
|
||||
if bs_val.annotations().slice().len() > 0 {
|
||||
return Err(self.syntax_error("Annotations not permitted after #="));
|
||||
}
|
||||
|
|
|
@ -23,11 +23,11 @@ fn decode_all(bytes: &'_ [u8]) -> io::Result<Vec<IOValue>> {
|
|||
let mut fh = std::fs::File::open("../../../tests/samples.pr").unwrap();
|
||||
let mut contents = String::new();
|
||||
fh.read_to_string(&mut contents)?;
|
||||
BytesBinarySource::new(contents.as_bytes()).text().next_iovalue(true)?
|
||||
BytesBinarySource::new(contents.as_bytes()).text().demand_next_iovalue(true)?
|
||||
};
|
||||
let from_packed = {
|
||||
let mut fh = std::fs::File::open("../../../tests/samples.bin").unwrap();
|
||||
IOBinarySource::new(&mut fh).packed().next_iovalue(true)?
|
||||
IOBinarySource::new(&mut fh).packed().demand_next_iovalue(true)?
|
||||
};
|
||||
assert_eq!(from_text, from_packed);
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue