2 releases

Uses old Rust 2015

0.2.1 Oct 18, 2019
0.2.0 Oct 18, 2019

#359 in Profiling

Download history 4/week @ 2024-01-08 15/week @ 2024-02-12 25/week @ 2024-02-19 29/week @ 2024-02-26 6/week @ 2024-03-04 15/week @ 2024-03-11 9/week @ 2024-03-18

61 downloads per month
Used in bevy_pkv

MIT/Apache

19KB
106 lines

This is a wasm32 browser friendly version of easybench

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 web_sys::console;
use easybench_wasm::{bench,bench_env};

// Simple benchmarks are performed with `bench`.
console::log_1(&format!("fib 200: {}", bench(|| fib(200) )).into());
console::log_1(&format!("fib 500: {}", bench(|| fib(500) )).into());

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

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.

Dependencies

~6.5–9MB
~173K SLoC