| Crates.io | benchmark_suite |
| lib.rs | benchmark_suite |
| version | 0.1.0 |
| created_at | 2023-05-05 05:30:42.5129+00 |
| updated_at | 2023-05-05 05:30:42.5129+00 |
| description | Quickly collect benchmarking information with complete I/O control |
| homepage | |
| repository | https://github.com/JamieH01/benchmark_suite |
| max_upload_size | |
| id | 857302 |
| size | 14,327 |
Quickly and easily benchmark code, with complete control over I/O generation and built-in multithreading.
To use Benchmarker, your input data must be inside of a struct that implements Bench. This allows complete control over how your inputs are generated for each test (i.e. using rand).
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;
}
}
}
}
}
Now, you can create the benchmarker with the quickbench! macro, and run a test with start(). Starting another test after will continue to add to the list of times, making them more detailed.
//note that the runcount is the amount of times threads are created, the total number of tests ran is threads * runcount
//struct, threads, runcount
let mut bencher = quickbench!(Sorter, 8, 100);
bencher.start();
println!(
"{:?} / {}",
bencher.average(),
bencher.max_threads * bencher.max_runcount,
)