use criterion::{criterion_group, criterion_main, Criterion}; use itertools::{Itertools, cloned};
trait IterEx : Iterator { // Another efficient implementation against which to compare, // but needs `std` so is less desirable. fn tree_fold1_vec<F>(self, mut f: F) -> Option<Self::Item> where F: FnMut(Self::Item, Self::Item) -> Self::Item, Self: Sized,
{ let hint = self.size_hint().0; let cap = std::mem::size_of::<usize>() * 8 - hint.leading_zeros() as usize; letmut stack = Vec::with_capacity(cap); self.enumerate().for_each(|(mut i, mut x)| { while (i & 1) != 0 {
x = f(stack.pop().unwrap(), x);
i >>= 1;
}
stack.push(x);
});
stack.into_iter().fold1(f)
}
} impl<T:Iterator> IterEx for T {}
pubfn complex_iter(c: &mut Criterion) { let u = (3..).take($N / 2); let v = (5..).take($N / 2); let it = u.chain(v);
c.bench_function(&(stringify!($BENCH_NAME).replace('_', " ") + " complex iter"), move |b| {
b.iter(|| {
it.clone().map(|x| x as f32).$FUN(f32::atan2)
})
});
}
pubfn string_format(c: &mut Criterion) { // This goes quadratic with linear `fold1`, so use a smaller // size to not waste too much time in travis. The allocations // in here are so expensive anyway that it'll still take // way longer per iteration than the other two benchmarks. let v: Vec<u32> = (0.. ($N/4)).collect();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.