easybench

Crates.ioeasybench
lib.rseasybench
version1.1.1
sourcesrc
created_at2017-03-29 04:21:17.384836
updated_at2023-04-28 07:56:33.807297
descriptionA lightweight benchmarking library
homepage
repositoryhttps://github.com/asayers/easybench-rs
max_upload_size
id9223
size31,346
CI (github:colearn-dev:ci)

documentation

https://docs.rs/easybench/

README

A lightweight benchmarking library which:

  • uses linear regression to screen off sources of constant error;
  • handles benchmarks which must mutate some state;
  • has a very simple API!
use easybench::{bench,bench_env};

// Simple benchmarks are performed with `bench`.
println!("fib 200: {}", bench(|| fib(200) ));
println!("fib 500: {}", bench(|| fib(500) ));

// If a function needs to mutate some state, use `bench_env`.
println!("reverse: {}", bench_env(vec![1,2,3], |xs| xs.reverse()));
println!("sort:    {}", bench_env(vec![1,2,3], |xs| xs.sort()));

Running the above yields the following:

fib 200:         38 ns   (R²=1.000, 26053498 iterations in 155 samples)
fib 500:        109 ns   (R²=1.000, 9131585 iterations in 144 samples)
reverse:          3 ns   (R²=0.998, 23684997 iterations in 154 samples)
sort:             3 ns   (R²=0.999, 23684997 iterations in 154 samples)

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 46

cargo fmt