111 lines
3.0 KiB
Rust
111 lines
3.0 KiB
Rust
use criterion::{Criterion, criterion_group, criterion_main};
|
|
use std::{hint::black_box, time::Duration};
|
|
use weaponry::{
|
|
interfaces::RecipeCollection,
|
|
weaponry_structs::{Equipement, InitialEquipementList},
|
|
};
|
|
|
|
fn criterion_benchmark(c: &mut Criterion) {
|
|
let blk_steps = [
|
|
InitialEquipementList::from_vectored(vec![Equipement::default(); 100]),
|
|
InitialEquipementList::from_vectored(vec![Equipement::default(); 100]),
|
|
InitialEquipementList::from_vectored(vec![Equipement::default(); 100]),
|
|
];
|
|
c.bench_function("creating 100 Elements", |b| {
|
|
b.iter(|| {
|
|
InitialEquipementList::from_vectored(black_box(vec![
|
|
black_box(Equipement::default());
|
|
100
|
|
]))
|
|
})
|
|
});
|
|
c.bench_function("IterGenBlanket: 100x100x100", |b| {
|
|
b.iter(|| {
|
|
let mut s = blk_steps[0].clone();
|
|
s.combine_all(black_box(&blk_steps[1]));
|
|
s.combine_all(black_box(&blk_steps[2]));
|
|
})
|
|
});
|
|
// c.bench_function("IterGen: 100x100x100x100", |b| {
|
|
// b.iter(|| {
|
|
// let mut s = steps[0].clone();
|
|
// s.combine_all(steps[1].clone());
|
|
// s.combine_all(steps[2].clone());
|
|
// s.combine_all(steps[2].clone());
|
|
// })
|
|
// });
|
|
// c.bench_function("IterGenPar: 100x100x100x100", |b| {
|
|
// b.iter(|| {
|
|
// let mut s = par_steps[0].clone();
|
|
// s.combine_all(par_steps[1].clone());
|
|
// s.combine_all(par_steps[2].clone());
|
|
// s.combine_all(par_steps[2].clone());
|
|
// })
|
|
// });
|
|
}
|
|
|
|
criterion_group! {
|
|
name = benches;
|
|
config = Criterion::default().measurement_time(Duration::from_secs(10));
|
|
targets= criterion_benchmark
|
|
}
|
|
criterion_main!(benches);
|
|
|
|
// TODO: Add to a How to add new Lists
|
|
|
|
// #[derive(Clone)]
|
|
// struct Equipo {
|
|
// stats: InnerStats,
|
|
// }
|
|
|
|
// impl Equipo {
|
|
// fn newish(i: u8) -> Self {
|
|
// let mut stats = InnerStats::default();
|
|
// stats.id = i;
|
|
// Equipo { stats }
|
|
// }
|
|
// }
|
|
|
|
// struct ListStatic {
|
|
// inner: Vec<Equipo>,
|
|
// }
|
|
// struct ListParIter {
|
|
// inner: Vec<Equipo>,
|
|
// }
|
|
|
|
// impl RecipeCollection for ListStatic {
|
|
// type Recipes = Equipo;
|
|
|
|
// fn combine_all<G>(&mut self, other: G)
|
|
// where
|
|
// G: RecipeCollection<Recipes = Self::Recipes>,
|
|
// {
|
|
// todo!()
|
|
// }
|
|
|
|
// fn inner(&self) -> Vec<Self::Recipes> {
|
|
// self.inner.clone()
|
|
// }
|
|
|
|
// fn from_vectored(list: Vec<Self::Recipes>) -> Self {
|
|
// Self { inner: list }
|
|
// }
|
|
// }
|
|
|
|
// impl Combineable for Equipo {
|
|
// type Inner = InnerStats;
|
|
|
|
// fn clone_combinable_part(&self) -> Self::Inner {
|
|
// self.stats.clone()
|
|
// }
|
|
|
|
// fn add_to_self<T>(&self, rhs: T) -> Self
|
|
// where
|
|
// T: Combineable<Inner = Self::Inner>,
|
|
// {
|
|
// Equipo {
|
|
// stats: self.clone_combinable_part() + rhs.clone_combinable_part(),
|
|
// }
|
|
// }
|
|
// }
|