Struct pew::Benchmark [] [src]

pub struct Benchmark<T: 'static + Clone> { /* fields omitted */ }

The main Benchmark struct

A benchmark consists of the following:

  • name: &'static str - will be prefixed to the output (see run)
  • One or more bench: fn(&mut State<T>) which are the actual benchmark. This is the actual benchmark which is timed
  • A range which consists of a lower_bound, an upper_bound, and a mul factor. Will run the benchmark once for each i in [lower_bound, upperbound] such that i is initialized to lower_bound and gets multiplied by mul. Defaults to:
    • lower_bound = 1
    • upper_bound = 1 << 20
    • mul = 2
  • generator: fn(u64) -> T (optional) - rather than passing i from above as input to the benchmark, T produced by this method is passed in instead. For each i, gen(i) is called once for each bench in this benchmark. The result of this is then cloned and passed into bench each time it is run.

Examples

#[macro_use]
extern crate pew;
use pew::Benchmark;

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

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());
    }
}

fn main() {
    Benchmark::with_name("range_bench")
        .with_range(1 << 5, 1 << 5, 2)
        .with_generator(get_vec)
        .with_bench(pew_bench!(bm_vector_gen))
        .run();
}

This will output:

Name,Time (ns)
gen_bench/f/1024,103674
gen_bench/f/4096,412499
gen_bench/f/16384,1634809
gen_bench/f/65536,7168879
gen_bench/f/262144,27419824
gen_bench/f/1048576,109010591

See examples/ for more examples.

Methods

impl Benchmark<u64>
[src]

[src]

Generates a new benchmark with name

impl<T: Clone> Benchmark<T>
[src]

[src]

Sets the lower_bound for this benchmark

[src]

Sets the upper_bound for this benchmark

[src]

Sets the mul for this benchmark

[src]

Sets the entire range for this benchmark

[src]

Sets a generator for this benchmark

Multiple generators can be specified, each of which will be fn(T) -> U. These will be composed with the previous generators.

Note that calling this function will wipe out all previously set benches. Therefore, this function should be called before calling with_bench.

[src]

Specifies a benchmark method

This must be called one or more times before calling run. All functions in this suite will have the same range and generator(s).

This accepts a tuple with the benchmark name and the function. If the function is an ident and you want the benchmark name to match the function, use pew_bench!.

[src]

Runs the benchmark

Prints the result as a csv with the following format:

  • Header which will be exactly Name,Time(ns) (this will be printed once for the whole program, not once per call to run).
  • Rows where
    • name will be a slash separated concatenation of the benchmark name, the function name, and i
    • time will be the time in nanoseconds for running the benchmark

Panics

Panics if no bench methods are specified.

Trait Implementations

Auto Trait Implementations

impl<T> !Send for Benchmark<T>

impl<T> !Sync for Benchmark<T>