use criterion::{criterion_group, criterion_main, Criterion}; use allsorts::binary::read::ReadScope; use allsorts::binary::U16Be; fn buffer() -> Vec { vec![ 0xc8, 0x8f, 0xc0, 0xd8, 0x84, 0xfc, 0x6b, 0x73, 0xf8, 0x4d, 0xd0, 0x19, 0xfe, 0xf7, 0x64, 0x4e, 0x27, 0x50, 0x42, 0x75, 0xc0, 0x83, 0x77, 0x53, 0x8f, 0x47, 0x7a, 0xb2, 0x98, 0xbd, 0xa9, 0x6a, 0x49, 0xa5, 0x4a, 0xec, 0x41, 0xbf, 0x23, 0xfc, 0xaf, 0x5c, 0x5c, 0x6f, 0xb2, 0xeb, 0x66, 0xe3, 0x42, 0x8b, 0xf2, 0x9b, 0x26, 0xfd, 0xb2, 0xf6, 0x66, 0x11, 0x75, 0x4c, 0xcf, 0xa6, 0x34, 0xba, 0xd0, 0x71, 0xc7, 0x2b, 0x6c, 0xda, 0x77, 0x71, 0x5e, 0xfe, 0x49, 0xec, 0x83, 0x5c, 0x7c, 0xd2, 0xc5, 0xfb, 0x3f, 0xe9, 0x54, 0xcd, 0xbd, 0xe7, 0x59, 0x07, 0x1c, 0x95, 0x79, 0xad, 0xde, 0x61, 0x23, 0x9a, 0xb2, 0xaf, 0x57, 0x74, 0x40, 0xb2, 0xfb, 0xea, 0xba, 0x25, 0x84, 0x73, 0x54, 0x7b, 0x85, 0xc7, 0x0e, 0x83, 0x6d, 0xdb, 0xcc, 0xa0, 0x88, 0x66, 0x35, 0x66, 0xda, 0xff, 0x82, 0x02, 0x54, 0x46, 0xca, 0x1f, 0x74, 0xc8, 0x8b, 0xe0, 0xc5, 0xc9, 0x58, 0xb3, 0x4a, 0xf4, 0x10, 0x64, 0x87, 0x6f, 0x1c, 0x28, 0x4e, 0x32, 0x97, 0x89, 0xf4, 0xa6, 0x84, 0x4a, 0x58, 0x7e, 0x31, 0xd1, 0x6f, 0x1c, 0x28, 0x4e, 0x32, ] } fn benchmarks(c: &mut Criterion) { c.bench_function("read_array collect", |b| { let buf = buffer(); b.iter(|| { let mut ctxt = ReadScope::new(&buf).ctxt(); let len = buf.len() / 2; let _substitute_glyph_array = ctxt .read_array::(len) .unwrap() .iter() .collect::>(); }) }); c.bench_function("read_array to_vec", |b| { let buf = buffer(); b.iter(|| { let mut ctxt = ReadScope::new(&buf).ctxt(); let len = buf.len() / 2; let _substitute_glyph_array = ctxt.read_array::(len).unwrap().to_vec(); }) }); } criterion_group!(benches, benchmarks); criterion_main!(benches);