#benchmark #bench #simple

无std dev benchmark-simple

一个微小、极其简单且便携的基准测试库

10个版本

0.1.9 2024年2月9日
0.1.8 2023年5月23日
0.1.7 2021年10月20日

#86WebAssembly

Download history 30/week @ 2024-04-08 87/week @ 2024-04-15 71/week @ 2024-04-22 35/week @ 2024-04-29 38/week @ 2024-05-06 55/week @ 2024-05-13 46/week @ 2024-05-20 32/week @ 2024-05-27 86/week @ 2024-06-03 49/week @ 2024-06-10 39/week @ 2024-06-17 67/week @ 2024-06-24 50/week @ 2024-07-08 72/week @ 2024-07-15 24/week @ 2024-07-22

每月 156 次下载
用于 17 crates

MIT 许可证

14KB
245 代码行

benchmark-simple

Rust的一个微小基准测试库。

  • 易于使用
  • 几乎在所有地方都能工作,包括WebAssembly(WASI,也支持浏览器)
use benchmark_simple::*;

fn test_function() {
    // ...
}

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

吞吐量计算

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

选项

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,
}

通过在Options结构中将verbose设置为true或在环境中定义一个BENCHMARK_VERBOSE变量,可以使基准测试结果更详细。

依赖

~16–375KB