#benchmark #bench #execution #time

benchmarking

This crate can be used to execute something and measure the execution time. It does not output anything to screens and filesystems.

7 releases

✓ Uses Rust 2018 edition

0.4.6 Sep 16, 2019
0.4.5 Sep 15, 2019
0.4.4 Jul 28, 2019
0.4.3 Jun 8, 2019
0.1.2 Jun 4, 2019

#11 in Profiling

Download history 40/week @ 2019-07-31 50/week @ 2019-08-07 9/week @ 2019-08-14 54/week @ 2019-08-21 37/week @ 2019-08-28 97/week @ 2019-09-04 48/week @ 2019-09-11 298/week @ 2019-09-18 43/week @ 2019-09-25 37/week @ 2019-10-02 6/week @ 2019-10-09 73/week @ 2019-10-16 60/week @ 2019-10-23 40/week @ 2019-10-30 5/week @ 2019-11-06

272 downloads per month
Used in 1 crate

MIT license

27KB
565 lines

Benchmarking

Build Status

This crate can be used to execute something and measure the execution time. It does not output anything to screens and filesystems.

Examples

extern crate benchmarking;

const VEC_LENGTH: usize = 100;

benchmarking::warm_up();

let bench_result = benchmarking::measure_function(|measurer| {
    let mut vec: Vec<usize> = Vec::with_capacity(VEC_LENGTH);

    unsafe {
        vec.set_len(VEC_LENGTH);
    }

    for i in 0..VEC_LENGTH {
        measurer.measure(|| {
            vec[i]
        });
    }

    vec
}).unwrap();

println!("Reading a number from a vec takes {:?}!", bench_result.elapsed());
extern crate benchmarking;

const VEC_LENGTH: usize = 100;

benchmarking::warm_up();

let bench_result = benchmarking::measure_function(|measurer| {
    let mut vec: Vec<usize> = Vec::with_capacity(VEC_LENGTH);

    measurer.measure(|| {
        for i in 0..VEC_LENGTH {
            vec.push(i);
        }
    });

    vec
}).unwrap();

println!("Filling 0 to 99 into a vec takes {:?}!", bench_result.elapsed());
extern crate benchmarking;

const VEC_LENGTH: usize = 100;

benchmarking::warm_up();

let bench_result = benchmarking::measure_function(|measurer| {
    let mut vec: Vec<usize> = Vec::with_capacity(VEC_LENGTH);

    for loop_seq in 0..VEC_LENGTH {
        measurer.measure(|| {
            vec.push(loop_seq);
        });
    }

    vec
}).unwrap();

println!("Pushing a number into a vec takes {:?}!", bench_result.elapsed());
extern crate benchmarking;

const VEC_LENGTH: usize = 100;

benchmarking::warm_up();

let bench_result = benchmarking::measure_function_n(2, |measurers| {
    let mut vec: Vec<usize> = Vec::with_capacity(VEC_LENGTH);

    for i in 0..VEC_LENGTH {
        measurers[1].measure(|| {
            vec.push(i);
        });
    }

    for i in 0..VEC_LENGTH {
        measurers[0].measure(|| {
            vec[i]
        });
    }

    vec
}).unwrap();

println!("Reading a number from a vec takes {:?}!", bench_result[0].elapsed());
println!("Pushing a number into a vec takes {:?}!", bench_result[1].elapsed());
  • The warm_up and warm_up_with_duration functions of the benchmarking crate runs on one thread. To warm up all CPUs, you can use the warm_up_multi_thread and warm_up_multi_thread_with_duration functions instead.
  • The measure_function and measure_function_with_times functions of the benchmarking crate can execute a closure for N times. To execute it repeatly for a while instead, you can use the bench_function and bench_function_with_duration functions.
  • To execute a closure with multiple threads to measure the throughput, you can use the multi_thread_bench_function and multi_thread_bench_function_with_duration functions of the benchmarking crate.

Crates.io

https://crates.io/crates/benchmarking

Documentation

https://docs.rs/benchmarking

License

MIT

No runtime deps