use criterion::*; use petscii::{encode, decode, PetsciiString}; pub fn criterion_encode(c: &mut Criterion) { let d: String = (0..1024).map(|_| 0x00..0xff).flatten().flat_map(|c| petscii::PETSCII[c]).collect(); c.bench_function("encode", |b| b.iter(|| encode(black_box(&d)))); } pub fn criterion_decode(c: &mut Criterion) { let d: Vec = (0..1024).map(|_| 0x00..0xff).flatten().collect(); c.bench_function("decode", |b| b.iter(|| decode(black_box(&d), black_box(d.len())))); } pub fn criterion_petscii_try_from(c: &mut Criterion) { let d: String = (0..1024).map(|_| 0x00..0xff).flatten().flat_map(|c| petscii::PETSCII[c]).collect(); c.bench_function("PetsciiString::try_from", |b| b.iter(|| PetsciiString::try_from(&d).unwrap())); } pub fn criterion_petscii_into(c: &mut Criterion) { let d: Vec = (0..1024).map(|_| 0x00..0xff).flatten().collect(); let p = PetsciiString::from(&d as &[u8]); c.bench_function("PetsciiString::into", |b| b.iter(|| { let _: String = p.clone().into(); })); } criterion_group!(benches, criterion_encode, criterion_decode, criterion_petscii_try_from, criterion_petscii_into); criterion_main!(benches);