diff options
Diffstat (limited to 'ecs/benches/query.rs')
-rw-r--r-- | ecs/benches/query.rs | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/ecs/benches/query.rs b/ecs/benches/query.rs new file mode 100644 index 0000000..0f18f5c --- /dev/null +++ b/ecs/benches/query.rs @@ -0,0 +1,141 @@ +use std::hint::black_box; +use std::path::PathBuf; + +use criterion::{criterion_group, criterion_main, Criterion}; +use ecs::{Component, World}; + +#[derive(Component)] +struct Foo +{ + _text: String, +} + +#[derive(Component)] +struct Bar +{ + _path: PathBuf, + _num: u64, +} + +#[derive(Component)] +struct Position +{ + _x: f32, + _y: f32, + _z: f32, +} + +#[derive(Component)] +struct PosA +{ + _x: f32, + _y: f32, + _z: f32, +} + +#[derive(Component)] +struct PosB +{ + _x: f32, + _y: f32, + _z: f32, +} + +#[derive(Component)] +struct PosC +{ + _x: f32, + _y: f32, + _z: f32, +} + +#[derive(Component)] +struct MoreText +{ + _more_text: String, +} + +#[derive(Component)] +struct EvenMoreText +{ + _even_more_text: String, +} + +fn spawn_1000_entities(world: &mut World) +{ + for _ in 0..300 { + world.create_entity(( + Bar { + _path: "/dev/zero".into(), + _num: 65789, + }, + Position { _x: 13.98, _y: 27.0, _z: 0.2 }, + Foo { _text: "Hello there".to_string() }, + PosA { + _x: 1183.98, + _y: 272628.0, + _z: 3306.2, + }, + PosB { + _x: 171183.98, + _y: 28.0, + _z: 336.2901, + }, + PosC { _x: 8273.98, _y: 28.0, _z: 336.2901 }, + MoreText { + _more_text: "Lorem ipsum".to_string(), + }, + EvenMoreText { + _even_more_text: "Wow so much text".to_string(), + }, + )); + } + + for _ in 0..700 { + world.create_entity(( + Bar { + _path: "/dev/null".into(), + _num: 65789, + }, + Position { _x: 88.11, _y: 9.0, _z: 36.11 }, + Foo { _text: "Hey".to_string() }, + PosA { + _x: 118310.98, + _y: 272628.0, + _z: 3306.2, + }, + PosB { _x: 11323.98, _y: 28.0, _z: 336.2901 }, + PosC { + _x: 8273.98, + _y: 21818.0, + _z: 336.2901, + }, + MoreText { + _more_text: "Lorem ipsum".to_string(), + }, + EvenMoreText { + _even_more_text: "Wow much text".to_string(), + }, + )); + } +} + +fn benchbark(criterion: &mut Criterion) +{ + criterion.bench_function("Iterate 1000 entities", |bencher| { + let mut world = World::new(); + + spawn_1000_entities(&mut world); + + let query = world.query::<(Bar, Position, Foo), ()>(); + + bencher.iter(|| { + for comps in query.iter() { + black_box(comps); + } + }) + }); +} + +criterion_group!(benches, benchbark); +criterion_main!(benches); |