Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Despawn and despawn_recursive benchmarks #15610

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions benches/benches/bevy_ecs/world/despawn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use bevy_ecs::prelude::*;
use criterion::Criterion;
use glam::*;

#[derive(Component)]
struct A(Mat4);
#[derive(Component)]
struct B(Vec4);

pub fn world_despawn(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("despawn_world");
group.warm_up_time(core::time::Duration::from_millis(500));
group.measurement_time(core::time::Duration::from_secs(4));

for entity_count in (0..5).map(|i| 10_u32.pow(i)) {
let mut world = World::default();
for _ in 0..entity_count {
world.spawn((A(Mat4::default()), B(Vec4::default())));
}

let ents = world.iter_entities().map(|e| e.id()).collect::<Vec<_>>();
group.bench_function(format!("{}_entities", entity_count), |bencher| {
bencher.iter(|| {
ents.iter().for_each(|e| {
world.despawn(*e);
});
});
});
}

group.finish();
}
33 changes: 33 additions & 0 deletions benches/benches/bevy_ecs/world/despawn_recursive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use bevy_ecs::prelude::*;
use bevy_hierarchy::despawn_with_children_recursive;
use criterion::Criterion;
use glam::*;

#[derive(Component)]
struct A(Mat4);
#[derive(Component)]
struct B(Vec4);

pub fn world_despawn_recursive(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("despawn_world_recursive");
group.warm_up_time(core::time::Duration::from_millis(500));
group.measurement_time(core::time::Duration::from_secs(4));

for entity_count in (0..5).map(|i| 10_u32.pow(i)) {
let mut world = World::default();
for _ in 0..entity_count {
world.spawn((A(Mat4::default()), B(Vec4::default())));
}

let ents = world.iter_entities().map(|e| e.id()).collect::<Vec<_>>();
group.bench_function(format!("{}_entities", entity_count), |bencher| {
bencher.iter(|| {
ents.iter().for_each(|e| {
despawn_with_children_recursive(&mut world, *e);
});
});
});
}

group.finish();
}
8 changes: 8 additions & 0 deletions benches/benches/bevy_ecs/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ use criterion::criterion_group;
mod commands;
use commands::*;

mod despawn;
use despawn::*;

mod despawn_recursive;
use despawn_recursive::*;

mod spawn;
use spawn::*;

Expand All @@ -28,6 +34,8 @@ criterion_group!(
world_query_iter,
world_query_for_each,
world_spawn,
world_despawn,
world_despawn_recursive,
query_get,
query_get_many::<2>,
query_get_many::<5>,
Expand Down