8 releases (3 stable)

1.1.1 Apr 28, 2023
1.1.0 Dec 27, 2020
1.0.0 Nov 7, 2019
0.1.4 Jul 12, 2018
0.1.2 Mar 31, 2017

#24 in Profiling

Download history 599/week @ 2023-11-27 200/week @ 2023-12-04 452/week @ 2023-12-11 237/week @ 2023-12-18 29/week @ 2023-12-25 295/week @ 2024-01-01 540/week @ 2024-01-08 439/week @ 2024-01-15 439/week @ 2024-01-22 501/week @ 2024-01-29 954/week @ 2024-02-05 1098/week @ 2024-02-12 1027/week @ 2024-02-19 898/week @ 2024-02-26 937/week @ 2024-03-04 381/week @ 2024-03-11

3,250 downloads per month
Used in 9 crates

MIT/Apache

20KB
208 lines

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.

No runtime deps