forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cart's fork of ecs_bench_suite (bevyengine#4225)
# Objective Better benchmarking for ECS. Fix bevyengine#2062. ## Solution Port @cart's fork of ecs_bench_suite to the official bench suite for bevy_ecs, replace cgmath with glam, update to latest bevy.
- Loading branch information
Showing
22 changed files
with
996 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use bevy::prelude::*; | ||
|
||
#[derive(Component)] | ||
struct A(f32); | ||
#[derive(Component)] | ||
struct B(f32); | ||
|
||
pub struct Benchmark(World, Vec<Entity>); | ||
|
||
impl Benchmark { | ||
pub fn new() -> Self { | ||
let mut world = World::default(); | ||
|
||
let entities = world | ||
.spawn_batch((0..10000).map(|_| (A(0.0),))) | ||
.collect::<Vec<_>>(); | ||
|
||
Self(world, entities) | ||
} | ||
|
||
pub fn run(&mut self) { | ||
for entity in &self.1 { | ||
self.0.insert_one(*entity, B(0.0)).unwrap(); | ||
} | ||
|
||
for entity in &self.1 { | ||
self.0.remove_one::<B>(*entity).unwrap(); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
benches/benches/bevy_ecs/ecs_bench_suite/add_remove_big_sparse_set.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use bevy_ecs::prelude::*; | ||
use glam::*; | ||
|
||
#[derive(Component, Copy, Clone)] | ||
struct A(Mat4); | ||
#[derive(Component, Copy, Clone)] | ||
struct B(Mat4); | ||
|
||
#[derive(Component, Copy, Clone)] | ||
struct C(Mat4); | ||
#[derive(Component, Copy, Clone)] | ||
struct D(Mat4); | ||
|
||
#[derive(Component, Copy, Clone)] | ||
struct E(Mat4); | ||
|
||
#[derive(Component, Copy, Clone)] | ||
#[component(storage = "SparseSet")] | ||
struct F(Mat4); | ||
pub struct Benchmark(World, Vec<Entity>); | ||
|
||
impl Benchmark { | ||
pub fn new() -> Self { | ||
let mut world = World::default(); | ||
let mut entities = Vec::with_capacity(10_000); | ||
for _ in 0..10_000 { | ||
entities.push( | ||
world | ||
.spawn() | ||
.insert_bundle(( | ||
A(Mat4::from_scale(Vec3::ONE)), | ||
B(Mat4::from_scale(Vec3::ONE)), | ||
C(Mat4::from_scale(Vec3::ONE)), | ||
D(Mat4::from_scale(Vec3::ONE)), | ||
E(Mat4::from_scale(Vec3::ONE)), | ||
)) | ||
.id(), | ||
); | ||
} | ||
|
||
Self(world, entities) | ||
} | ||
|
||
pub fn run(&mut self) { | ||
for entity in &self.1 { | ||
self.0 | ||
.entity_mut(*entity) | ||
.insert(F(Mat4::from_scale(Vec3::ONE))); | ||
} | ||
|
||
for entity in &self.1 { | ||
self.0.entity_mut(*entity).remove::<F>(); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
benches/benches/bevy_ecs/ecs_bench_suite/add_remove_big_table.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use bevy_ecs::prelude::*; | ||
use glam::*; | ||
|
||
#[derive(Component, Copy, Clone)] | ||
struct A(Mat4); | ||
#[derive(Component, Copy, Clone)] | ||
struct B(Mat4); | ||
|
||
#[derive(Component, Copy, Clone)] | ||
struct C(Mat4); | ||
#[derive(Component, Copy, Clone)] | ||
struct D(Mat4); | ||
|
||
#[derive(Component, Copy, Clone)] | ||
struct E(Mat4); | ||
|
||
#[derive(Component, Copy, Clone)] | ||
struct F(Mat4); | ||
pub struct Benchmark(World, Vec<Entity>); | ||
|
||
impl Benchmark { | ||
pub fn new() -> Self { | ||
let mut world = World::default(); | ||
let mut entities = Vec::with_capacity(10_000); | ||
for _ in 0..10_000 { | ||
entities.push( | ||
world | ||
.spawn() | ||
.insert_bundle(( | ||
A(Mat4::from_scale(Vec3::ONE)), | ||
B(Mat4::from_scale(Vec3::ONE)), | ||
C(Mat4::from_scale(Vec3::ONE)), | ||
D(Mat4::from_scale(Vec3::ONE)), | ||
E(Mat4::from_scale(Vec3::ONE)), | ||
)) | ||
.id(), | ||
); | ||
} | ||
|
||
Self(world, entities) | ||
} | ||
|
||
pub fn run(&mut self) { | ||
for entity in &self.1 { | ||
self.0 | ||
.entity_mut(*entity) | ||
.insert(F(Mat4::from_scale(Vec3::ONE))); | ||
} | ||
|
||
for entity in &self.1 { | ||
self.0.entity_mut(*entity).remove::<F>(); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
benches/benches/bevy_ecs/ecs_bench_suite/add_remove_sparse_set.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use bevy_ecs::prelude::*; | ||
|
||
#[derive(Component)] | ||
struct A(f32); | ||
#[derive(Component)] | ||
#[component(storage = "SparseSet")] | ||
struct B(f32); | ||
|
||
pub struct Benchmark(World, Vec<Entity>); | ||
|
||
impl Benchmark { | ||
pub fn new() -> Self { | ||
let mut world = World::default(); | ||
let mut entities = Vec::with_capacity(10_000); | ||
for _ in 0..10_000 { | ||
entities.push(world.spawn().insert(A(0.0)).id()); | ||
} | ||
|
||
Self(world, entities) | ||
} | ||
|
||
pub fn run(&mut self) { | ||
for entity in &self.1 { | ||
self.0.entity_mut(*entity).insert(B(0.0)); | ||
} | ||
|
||
for entity in &self.1 { | ||
self.0.entity_mut(*entity).remove::<B>(); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
benches/benches/bevy_ecs/ecs_bench_suite/add_remove_table.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use bevy_ecs::prelude::*; | ||
|
||
#[derive(Component)] | ||
struct A(f32); | ||
#[derive(Component)] | ||
struct B(f32); | ||
|
||
pub struct Benchmark(World, Vec<Entity>); | ||
|
||
impl Benchmark { | ||
pub fn new() -> Self { | ||
let mut world = World::default(); | ||
let mut entities = Vec::with_capacity(10_000); | ||
for _ in 0..10_000 { | ||
entities.push(world.spawn().insert(A(0.0)).id()); | ||
} | ||
|
||
Self(world, entities) | ||
} | ||
|
||
pub fn run(&mut self) { | ||
for entity in &self.1 { | ||
self.0.entity_mut(*entity).insert(B(0.0)); | ||
} | ||
|
||
for entity in &self.1 { | ||
self.0.entity_mut(*entity).remove::<B>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use bevy_ecs::prelude::*; | ||
|
||
macro_rules! create_entities { | ||
($world:ident; $( $variants:ident ),*) => { | ||
$( | ||
#[derive(Component)] | ||
struct $variants(f32); | ||
for _ in 0..20 { | ||
$world.spawn().insert_bundle(($variants(0.0), Data(1.0))); | ||
} | ||
)* | ||
}; | ||
} | ||
|
||
#[derive(Component)] | ||
struct Data(f32); | ||
|
||
pub struct Benchmark<'w>(World, QueryState<&'w mut Data>); | ||
|
||
impl<'w> Benchmark<'w> { | ||
pub fn new() -> Self { | ||
let mut world = World::new(); | ||
|
||
create_entities!(world; A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z); | ||
|
||
let query = world.query::<&mut Data>(); | ||
Self(world, query) | ||
} | ||
|
||
pub fn run(&mut self) { | ||
for mut data in self.1.iter_mut(&mut self.0) { | ||
data.0 *= 2.0; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
benches/benches/bevy_ecs/ecs_bench_suite/frag_iter_foreach.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use bevy_ecs::prelude::*; | ||
|
||
macro_rules! create_entities { | ||
($world:ident; $( $variants:ident ),*) => { | ||
$( | ||
#[derive(Component)] | ||
struct $variants(f32); | ||
for _ in 0..20 { | ||
$world.spawn().insert_bundle(($variants(0.0), Data(1.0))); | ||
} | ||
)* | ||
}; | ||
} | ||
|
||
#[derive(Component)] | ||
struct Data(f32); | ||
|
||
pub struct Benchmark<'w>(World, QueryState<&'w mut Data>); | ||
|
||
impl<'w> Benchmark<'w> { | ||
pub fn new() -> Self { | ||
let mut world = World::new(); | ||
|
||
create_entities!(world; A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z); | ||
|
||
let query = world.query::<&mut Data>(); | ||
Self(world, query) | ||
} | ||
|
||
pub fn run(&mut self) { | ||
self.1.for_each_mut(&mut self.0, |mut data| { | ||
data.0 *= 2.0; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use bevy_ecs::prelude::*; | ||
|
||
#[derive(Component)] | ||
struct A(f32); | ||
|
||
pub struct Benchmark<'w>(World, Entity, QueryState<&'w mut A>); | ||
|
||
impl<'w> Benchmark<'w> { | ||
pub fn new() -> Self { | ||
let mut world = World::new(); | ||
|
||
let entity = world.spawn().insert(A(0.0)).id(); | ||
let query = world.query::<&mut A>(); | ||
Self(world, entity, query) | ||
} | ||
|
||
pub fn run(&mut self) { | ||
for _x in 0..100000 { | ||
let mut a = unsafe { self.2.get_unchecked(&mut self.0, self.1).unwrap() }; | ||
a.0 += 1.0; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
benches/benches/bevy_ecs/ecs_bench_suite/get_component_system.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use bevy_ecs::prelude::*; | ||
|
||
#[derive(Component)] | ||
struct A(f32); | ||
|
||
pub struct Benchmark(World, Entity, Box<dyn System<In = Entity, Out = ()>>); | ||
|
||
impl Benchmark { | ||
pub fn new() -> Self { | ||
let mut world = World::new(); | ||
|
||
let entity = world.spawn().insert(A(0.0)).id(); | ||
fn query_system(In(entity): In<Entity>, mut query: Query<&mut A>) { | ||
for _ in 0..100_000 { | ||
let mut a = query.get_mut(entity).unwrap(); | ||
a.0 += 1.0; | ||
} | ||
} | ||
|
||
let mut system = IntoSystem::into_system(query_system); | ||
system.initialize(&mut world); | ||
for archetype in world.archetypes().iter() { | ||
system.new_archetype(archetype); | ||
} | ||
Self(world, entity, Box::new(system)) | ||
} | ||
|
||
pub fn run(&mut self) { | ||
self.2.run(self.1, &mut self.0); | ||
} | ||
} |
Oops, something went wrong.