// Run and time a closure and print the results.
Run and time a closure and print the results.
Run and time a closure and print the results .
fn profile_code<F, R, G, Args, InArgs: Copy>(iterations: usize, 
    setup_args: InArgs, setup: &G, mut closure: F) -> (u64,u64,u64)
        where F: FnMut(Args) -> R, G: Fn(InArgs) -> Args {
    let mut accum_time = 0;
    let mut min_time = u64::max_value();
    let mut max_time = 0;
    for _ in 0..iterations { 
        let input = setup(setup_args);
        let start = time::precise_time_ns();
        closure(input);
        let end = time::precise_time_ns();
        let time = end - start;
        if time > max_time {
            max_time = time;
        }
        if time < min_time {
            min_time = time;
        }
        accum_time += time;
    }
    let avg_time = accum_time/iterations as u64;
    (avg_time,min_time,max_time)
}
fn profile_code < F , R , G , Args , InArgs : Copy > ( iterations : usize , setup_args : InArgs , setup : & G , mut closure : F ) -> ( u64 , u64 , u64 ) where F : FnMut ( Args ) -> R , G : Fn ( InArgs ) -> Args { let mut accum_time = 0 ; let mut min_time = u64 :: max_value ( ) ; let mut max_time = 0 ; for _ in 0 .. iterations { let input = setup ( setup_args ) ; let start = time :: precise_time_ns ( ) ; closure ( input ) ; let end = time :: precise_time_ns ( ) ; let time = end - start ; if time > max_time { max_time = time ; } if time < min_time { min_time = time ; } accum_time += time ; } let avg_time = accum_time / iterations as u64 ; ( avg_time , min_time , max_time ) }
Run and time a closure and print the results.
Run and time a closure and print the results .
iterations
usize
setup_args
InArgs
setup
&G
closure
F