Function tiny_bench::run_timed_from_iterator
source · pub fn run_timed_from_iterator<T, R, F: FnMut(R) -> T, It>(
iterator: It,
closure: F
) -> TimingDatawhere
It: Iterator<Item = R>,
Expand description
Drains an iterator and calls the closure with the yielded value, timing the closure’s execution.
use std::time::Duration;
use tiny_bench::run_timed_from_iterator;
let it = (0..100);
let mut v = Vec::with_capacity(100);
let mut counted_iterations = 0;
let data = run_timed_from_iterator(it, |i| {
v.push(i);
counted_iterations += 1;
});
assert_eq!(100, v.len());
assert_eq!(100, counted_iterations);
data.pretty_print();