Function scaling::bench_scaling_gen[][src]

pub fn bench_scaling_gen<G, F, I, O>(
    gen_env: G,
    f: F,
    nmin: usize
) -> ScalingStats where
    G: FnMut(usize) -> I,
    F: Fn(&mut I) -> O, 

Benchmark the power-law scaling of the function with generated input

This function is like bench_scaling, but uses a generating function to construct the input to your benchmarked function.

This function assumes that the function scales as 𝑶(𝑁ᴾ𝐸ᴺ). It conisders higher powers for faster functions, and tries to keep the measuring time around 10s. It measures the power ᴾ and exponential base 𝐸 based on n R² goodness of fit parameter.

Example

use scaling::bench_scaling_gen;

let summation = bench_scaling_gen(|n| vec![3.0; n], |v| v.iter().cloned().sum::<f64>(),0);
println!("summation: {}", summation);
assert_eq!(1, summation.scaling.power); // summation must run in linear time.

which gives output

summation:     43ns/N    (R²=0.996, 445 iterations in 29 samples)