Macro pew::pew_main [] [src]

macro_rules! pew_main {
    (@inner $f: ident -> RANGE$e: expr) => { ... };
    (@inner $f: ident -> GENRANGE$e: expr) => { ... };
    ($($f: ident -> $id: ident$e: expr),+) => { ... };
}

Generates the main method that runs the actual benchmarks.

Accepts a comma separated list of either of the following:

  • <func_ident> -> RANGE(<lower_bound_expr>, <upper_bound_expr>, <mul_expr>)
  • <func_ident> -> GENRANGE(<generator_func_ident>, <lower_bound_expr>, <upper_bound_expr>, <mul_expr>)

where:

  • func_ident is the name of a function in scope. If using RANGE, func_ident should have type Fn(&mut pew::State<u64>). If using GENRANGE, func_ident should have type Fn(&mut pew::State<T>) where T depends on the generator type (see below).
  • lower_bound_expr, upper_bound_expr, and mul_expr are all numerical types representing the lower, upper, and multiplcation value for the benchmark. If using RANGE, state.get_input() will return all values from i = lower_bound; i <= lower_bound; i *= mul. If using GENRANGE, the generator function will receives the aforementioned values.
  • generator_func_ident is the name of a function in scope. The function type should be Fn(n: usize) -> T for some T: Clone + Default. This function will be called once for every i in the range (see above). It will be generated once per benchmark and cloned every time if the benchmark is run multiple times. Note that cloning is not counted in the benchmark time.

Examples

use std::vec::Vec;


fn get_vec(n: usize) -> Vec<u64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(i as u64);
    }
    return vec;
}

fn bm_vector_range(state: &mut pew::State<u64>) {
    let input = state.get_input();
    state.pause();
    let mut vec = get_vec(input as usize);
    state.resume();
    for _ in 0..input {
        pew::do_not_optimize(vec.pop());
    }
}

fn bm_vector_gen(state: &mut pew::State<Vec<u64>>) {
    let mut vec = state.get_input();
    let n = vec.len() as u64;
    for _ in 0..n {
        pew::do_not_optimize(vec.pop());
    }
}

pew_main!(
    bm_vector_range -> RANGE(1<<10, 1 << 20, 4),
    bm_vector_gen -> GENRANGE(get_vec, 1<<10, 1<<20, 4)
);