#benchmark #simple #bench #output

no-std dev benchmark-simple

A tiny, super simple and portable benchmarking library

11 releases

0.1.10 Nov 5, 2024
0.1.9 Feb 9, 2024
0.1.8 May 23, 2023
0.1.7 Oct 20, 2021

#126 in WebAssembly

Download history 13/week @ 2025-01-27 41/week @ 2025-02-03 38/week @ 2025-02-10 51/week @ 2025-02-17 30/week @ 2025-02-24 98/week @ 2025-03-03 431/week @ 2025-03-10 432/week @ 2025-03-17 466/week @ 2025-03-24 1417/week @ 2025-03-31 2835/week @ 2025-04-07 655/week @ 2025-04-14 810/week @ 2025-04-21 889/week @ 2025-04-28 911/week @ 2025-05-05 2300/week @ 2025-05-12

4,980 downloads per month
Used in 19 crates

MIT license

15KB
299 lines

benchmark-simple

A tiny benchmarking library for Rust.

  • Trivial to use
  • Works pretty much everywhere, including WebAssembly (WASI, but also in-browser)
use benchmark_simple::*;

fn test_function() {
    // ...
}

let bench = Bench::new();
let options = Options::default();
let res = bench.run(&options, || test_function());
println!("result: {}", res);

Throughput computation:

use benchmark_simple::*;

fn test_function(m: &mut [u8]) {
    // ...
}

let mut m = vec![0u8; 1_000_000];
let bench = Bench::new();
let options = Options::default();
let res = bench.run(&options, || test_function(&mut m));
let throughput = res.throughput(m.len() as _);
println!("throughput: {}", throughput);

Options:

pub struct Options {
    /// Number of iterations to perform.
    pub iterations: u64,
    /// Number of warm-up iterations to perform.
    pub warmup_iterations: u64,
    /// Minimum number of samples to collect.
    pub min_samples: usize,
    /// Maximum number of samples to collect.
    pub max_samples: usize,
    /// Maximum RSD to tolerate (in 0...100).
    pub max_rsd: f64,
    /// Maximum benchmark duration time.
    pub max_duration: Option<std::time::Duration>,
    /// Verbose output
    pub verbose: bool,
}

Benchmark results can be made verbose by setting verbose to true in the Options struct, or by defining a BENCHMARK_VERBOSE environment variable.

Dependencies

~16–380KB