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 usingRANGE
,func_ident
should have typeFn(&mut pew::State<u64>)
. If usingGENRANGE
,func_ident
should have typeFn(&mut pew::State<T>)
whereT
depends on the generator type (see below).lower_bound_expr
,upper_bound_expr
, andmul_expr
are all numerical types representing the lower, upper, and multiplcation value for the benchmark. If usingRANGE
,state.get_input()
will return all values fromi = lower_bound; i <= lower_bound; i *= mul
. If usingGENRANGE
, the generator function will receives the aforementioned values.generator_func_ident
is the name of a function in scope. The function type should beFn(n: usize) -> T
for someT: Clone + Default
. This function will be called once for everyi
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) );