Expand description
This crate allows for fast benchmarking of both complex and simple structs/closures, with complete control over I/O. The BenchMarker struct can be created from any type that implements the Bench trait, which lets you dictate input generation and the actual test to be ran. Here is an example of a sorting algorithm implementation with the trait:
use rand::prelude::*;
use benchmark_suite::*;
struct Sorter {
table:Vec<u32>
}
impl Bench for Sorter {
fn generate() -> Self {
let mut rng = rand::thread_rng();
let mut table:Vec<u32> = (1..100).collect();
table.shuffle(&mut rng);
Sorter {table}
}
fn test(&mut self) {
let mut swapped = true;
while swapped {
swapped = false;
for i in 0..self.table.len()-1 {
let a = self.table[i];
let b = self.table[i+1];
if a > b {
swapped = true;
self.table[i] = b;
self.table[i+1] = a;
}
}
}
}
}
After that, initialize, run, and display a benchmarking test with the quickbench! macro or manually:
//note that the total number of tests ran will be threads * runcount
//manually
let mut benchmark = BenchMarker::<Sorter>::new(8, 50);
benchmark.start();
println!("{}", benchmark);
//with macro
//var name, struct, threads, runcount
quickbench!(benchmark, Sorter, 8, 50);
Macros§
Structs§
- Bench
Marker - The main benchmarking struct that manages running and storing tests.
Enums§
- Display
Cfg - The types of information a benchmark can display. The internal
display_config
vector dictates what is shown in what order. Change this to your hearts content.
Constants§
- DEFAULT
- default display config.
Traits§
- Bench
- The trait to implement for benchmarking.
generate()
is how the struct should be generated;test()
will be called on it.