use criterion::{black_box, criterion_group, criterion_main, Criterion}; use ordpath::{enc, OrdPath}; fn comparison(c: &mut Criterion) { for len in &[0, 10, 50, 100, 500, 1000] { let seq = (0..*len).collect::>(); let x = ::from_slice(&seq, enc::Default); let y = ::from_slice(&seq, enc::Default); c.bench_function(&format!("ordpath_comparison_{}", len), |b| { b.iter(|| { black_box(x.cmp(&y)); }) }); } } fn from_slice(c: &mut Criterion) { for len in &[0, 10, 50, 100, 500, 1000] { let s = (0..*len).collect::>(); c.bench_function(&format!("ordpath_from_slice_{}", len), |b| { b.iter(|| { black_box(::from_slice(&s, enc::Default)); }) }); } } fn from_str(c: &mut Criterion) { for len in &[0, 10, 50, 100, 500, 1000] { let s = (0..*len) .map(|x| x.to_string()) .collect::>() .join("."); c.bench_function(&format!("ordpath_from_str_{}", len), |b| { b.iter(|| { black_box(::from_str(&s, enc::Default)); }) }); } } fn is_ancestor_of(c: &mut Criterion) { for len in &[0, 10, 50, 100, 500, 1000] { let seq = (0..*len).collect::>(); let x = ::from_slice(&seq, enc::Default); let y = ::from_slice(&seq, enc::Default); c.bench_function(&format!("ordpath_is_ancestor_of_{}", len), |b| { b.iter(|| { black_box(x.is_ancestor_of(&y)); }) }); } } fn iteration(c: &mut Criterion) { for len in &[0, 10, 50, 100, 500, 1000] { let s = (0..*len).collect::>(); let p = ::from_slice(&s, enc::Default); c.bench_function(&format!("ordpath_iteration{}", len), |b| { b.iter(|| { for x in &p { black_box(x); } }) }); } } criterion_group!( benches, comparison, from_slice, from_str, is_ancestor_of, iteration, ); criterion_main!(benches);