mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
Use batch spawn in benchmarks (#11611)
# Objective - The benchmarks for `bevy_ecs`' `iter_simple` group use `for` loops instead of `World::spawn_batch`. - There's a TODO comment that says to batch spawn them. ## Solution - Replace the `for` loops with `World::spawn_batch`.
This commit is contained in:
parent
e3cf5f8fb2
commit
3d2d61d063
9 changed files with 45 additions and 45 deletions
|
@ -19,15 +19,15 @@ impl<'w> Benchmark<'w> {
|
|||
pub fn new() -> Self {
|
||||
let mut world = World::new();
|
||||
|
||||
// TODO: batch this
|
||||
for _ in 0..10_000 {
|
||||
world.spawn((
|
||||
world.spawn_batch(
|
||||
std::iter::repeat((
|
||||
Transform(Mat4::from_scale(Vec3::ONE)),
|
||||
Position(Vec3::X),
|
||||
Rotation(Vec3::X),
|
||||
Velocity(Vec3::X),
|
||||
));
|
||||
}
|
||||
))
|
||||
.take(10_000),
|
||||
);
|
||||
|
||||
let query = world.query::<(&Velocity, &mut Position)>();
|
||||
Self(world, query)
|
||||
|
|
|
@ -19,15 +19,15 @@ impl<'w> Benchmark<'w> {
|
|||
pub fn new() -> Self {
|
||||
let mut world = World::new();
|
||||
|
||||
// TODO: batch this
|
||||
for _ in 0..10_000 {
|
||||
world.spawn((
|
||||
world.spawn_batch(
|
||||
std::iter::repeat((
|
||||
Transform(Mat4::from_scale(Vec3::ONE)),
|
||||
Position(Vec3::X),
|
||||
Rotation(Vec3::X),
|
||||
Velocity(Vec3::X),
|
||||
));
|
||||
}
|
||||
))
|
||||
.take(10_000),
|
||||
);
|
||||
|
||||
let query = world.query::<(&Velocity, &mut Position)>();
|
||||
Self(world, query)
|
||||
|
|
|
@ -21,15 +21,15 @@ impl<'w> Benchmark<'w> {
|
|||
pub fn new() -> Self {
|
||||
let mut world = World::new();
|
||||
|
||||
// TODO: batch this
|
||||
for _ in 0..10_000 {
|
||||
world.spawn((
|
||||
world.spawn_batch(
|
||||
std::iter::repeat((
|
||||
Transform(Mat4::from_scale(Vec3::ONE)),
|
||||
Position(Vec3::X),
|
||||
Rotation(Vec3::X),
|
||||
Velocity(Vec3::X),
|
||||
));
|
||||
}
|
||||
))
|
||||
.take(10_000),
|
||||
);
|
||||
|
||||
let query = world.query::<(&Velocity, &mut Position)>();
|
||||
Self(world, query)
|
||||
|
|
|
@ -33,9 +33,8 @@ impl<'w> Benchmark<'w> {
|
|||
pub fn new() -> Self {
|
||||
let mut world = World::new();
|
||||
|
||||
// TODO: batch this
|
||||
for _ in 0..10_000 {
|
||||
world.spawn((
|
||||
world.spawn_batch(
|
||||
std::iter::repeat((
|
||||
Transform(Mat4::from_scale(Vec3::ONE)),
|
||||
Rotation(Vec3::X),
|
||||
Position::<0>(Vec3::X),
|
||||
|
@ -48,8 +47,9 @@ impl<'w> Benchmark<'w> {
|
|||
Velocity::<3>(Vec3::X),
|
||||
Position::<4>(Vec3::X),
|
||||
Velocity::<4>(Vec3::X),
|
||||
));
|
||||
}
|
||||
))
|
||||
.take(10_000),
|
||||
);
|
||||
|
||||
let query = world.query();
|
||||
Self(world, query)
|
||||
|
|
|
@ -35,9 +35,8 @@ impl<'w> Benchmark<'w> {
|
|||
pub fn new() -> Self {
|
||||
let mut world = World::new();
|
||||
|
||||
// TODO: batch this
|
||||
for _ in 0..10_000 {
|
||||
world.spawn((
|
||||
world.spawn_batch(
|
||||
std::iter::repeat((
|
||||
Transform(Mat4::from_scale(Vec3::ONE)),
|
||||
Rotation(Vec3::X),
|
||||
Position::<0>(Vec3::X),
|
||||
|
@ -50,8 +49,9 @@ impl<'w> Benchmark<'w> {
|
|||
Velocity::<3>(Vec3::X),
|
||||
Position::<4>(Vec3::X),
|
||||
Velocity::<4>(Vec3::X),
|
||||
));
|
||||
}
|
||||
))
|
||||
.take(10_000),
|
||||
);
|
||||
|
||||
let query = world.query();
|
||||
Self(world, query)
|
||||
|
|
|
@ -21,15 +21,15 @@ impl<'w> Benchmark<'w> {
|
|||
pub fn new() -> Self {
|
||||
let mut world = World::new();
|
||||
|
||||
// TODO: batch this
|
||||
for _ in 0..10_000 {
|
||||
world.spawn((
|
||||
world.spawn_batch(
|
||||
std::iter::repeat((
|
||||
Transform(Mat4::from_scale(Vec3::ONE)),
|
||||
Position(Vec3::X),
|
||||
Rotation(Vec3::X),
|
||||
Velocity(Vec3::X),
|
||||
));
|
||||
}
|
||||
))
|
||||
.take(10_000),
|
||||
);
|
||||
|
||||
let query = world.query::<(&Velocity, &mut Position)>();
|
||||
Self(world, query)
|
||||
|
|
|
@ -19,15 +19,15 @@ impl Benchmark {
|
|||
pub fn new() -> Self {
|
||||
let mut world = World::new();
|
||||
|
||||
// TODO: batch this
|
||||
for _ in 0..10_000 {
|
||||
world.spawn((
|
||||
world.spawn_batch(
|
||||
std::iter::repeat((
|
||||
Transform(Mat4::from_scale(Vec3::ONE)),
|
||||
Position(Vec3::X),
|
||||
Rotation(Vec3::X),
|
||||
Velocity(Vec3::X),
|
||||
));
|
||||
}
|
||||
))
|
||||
.take(10_000),
|
||||
);
|
||||
|
||||
fn query_system(mut query: Query<(&Velocity, &mut Position)>) {
|
||||
for (velocity, mut position) in &mut query {
|
||||
|
|
|
@ -33,9 +33,8 @@ impl<'w> Benchmark<'w> {
|
|||
pub fn new() -> Self {
|
||||
let mut world = World::new();
|
||||
|
||||
// TODO: batch this
|
||||
for _ in 0..10_000 {
|
||||
world.spawn((
|
||||
world.spawn_batch(
|
||||
std::iter::repeat((
|
||||
Transform(Mat4::from_scale(Vec3::ONE)),
|
||||
Rotation(Vec3::X),
|
||||
Position::<0>(Vec3::X),
|
||||
|
@ -48,8 +47,9 @@ impl<'w> Benchmark<'w> {
|
|||
Velocity::<3>(Vec3::X),
|
||||
Position::<4>(Vec3::X),
|
||||
Velocity::<4>(Vec3::X),
|
||||
));
|
||||
}
|
||||
))
|
||||
.take(10_000),
|
||||
);
|
||||
|
||||
let query = world.query();
|
||||
Self(world, query)
|
||||
|
|
|
@ -35,9 +35,8 @@ impl<'w> Benchmark<'w> {
|
|||
pub fn new() -> Self {
|
||||
let mut world = World::new();
|
||||
|
||||
// TODO: batch this
|
||||
for _ in 0..10_000 {
|
||||
world.spawn((
|
||||
world.spawn_batch(
|
||||
std::iter::repeat((
|
||||
Transform(Mat4::from_scale(Vec3::ONE)),
|
||||
Rotation(Vec3::X),
|
||||
Position::<0>(Vec3::X),
|
||||
|
@ -50,8 +49,9 @@ impl<'w> Benchmark<'w> {
|
|||
Velocity::<3>(Vec3::X),
|
||||
Position::<4>(Vec3::X),
|
||||
Velocity::<4>(Vec3::X),
|
||||
));
|
||||
}
|
||||
))
|
||||
.take(10_000),
|
||||
);
|
||||
|
||||
let query = world.query();
|
||||
Self(world, query)
|
||||
|
|
Loading…
Reference in a new issue