-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71bf07f
commit 873906c
Showing
2 changed files
with
112 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,106 @@ | ||
use bevy::ecs::{ | ||
system::{CommandQueue, Commands}, | ||
world::World, | ||
}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rand::{rngs::StdRng, RngCore, SeedableRng}; | ||
|
||
criterion_group!( | ||
benches, | ||
empty_commands, | ||
spawning_commands, | ||
rng_spawning_commands | ||
); | ||
criterion_main!(benches); | ||
|
||
struct A; | ||
struct B; | ||
struct C; | ||
|
||
fn empty_commands(criterion: &mut Criterion) { | ||
let mut group = criterion.benchmark_group("empty_commands"); | ||
group.warm_up_time(std::time::Duration::from_millis(500)); | ||
group.measurement_time(std::time::Duration::from_secs(3)); | ||
|
||
group.bench_function("empty_commands", |bencher| { | ||
let mut world = World::default(); | ||
let mut command_queue = CommandQueue::default(); | ||
|
||
bencher.iter(|| { | ||
command_queue.apply(&mut world); | ||
}); | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
fn spawning_commands(criterion: &mut Criterion) { | ||
let mut group = criterion.benchmark_group("spawning_commands"); | ||
group.warm_up_time(std::time::Duration::from_millis(500)); | ||
group.measurement_time(std::time::Duration::from_secs(3)); | ||
|
||
for i in (1..5).map(|i| i * 2) { | ||
let entity_count = i * 1000; | ||
|
||
group.bench_function(format!("spawn_{}_entities", entity_count), |bencher| { | ||
let mut world = World::default(); | ||
let mut command_queue = CommandQueue::default(); | ||
|
||
bencher.iter(|| { | ||
let mut commands = Commands::new(&mut command_queue, &world); | ||
for _ in 0..entity_count { | ||
commands.spawn().insert(A).insert(B).insert(C).despawn(); | ||
} | ||
drop(commands); | ||
command_queue.apply(&mut world); | ||
}); | ||
}); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
fn rng_spawning_commands(criterion: &mut Criterion) { | ||
let mut group = criterion.benchmark_group("spawning_commands"); | ||
group.warm_up_time(std::time::Duration::from_millis(500)); | ||
group.measurement_time(std::time::Duration::from_secs(3)); | ||
|
||
for i in (1..5).map(|i| i * 2) { | ||
let entity_count = i * 1000; | ||
|
||
group.bench_function(format!("spawn_{}_entities_rng", entity_count), |bencher| { | ||
let mut world = World::default(); | ||
let mut command_queue = CommandQueue::default(); | ||
|
||
let mut rng = StdRng::seed_from_u64(42); | ||
let mut rng_bool = || rng.next_u32() % 2 == 0; | ||
|
||
bencher.iter(|| { | ||
let mut commands = Commands::new(&mut command_queue, &world); | ||
for _ in 0..entity_count { | ||
let mut entity = commands.spawn(); | ||
|
||
if rng_bool() { | ||
entity.insert(A); | ||
} | ||
|
||
if rng_bool() { | ||
entity.insert(B); | ||
} | ||
|
||
if rng_bool() { | ||
entity.insert(C); | ||
} | ||
|
||
if rng_bool() { | ||
entity.despawn(); | ||
} | ||
} | ||
drop(commands); | ||
command_queue.apply(&mut world); | ||
}); | ||
}); | ||
} | ||
|
||
group.finish(); | ||
} |