Skip to content

Commit

Permalink
add fake commands benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanSWard committed Jun 14, 2021
1 parent 86da923 commit 77a777f
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions benches/benches/bevy_ecs/commands.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use bevy::ecs::{
system::{CommandQueue, Commands},
system::{Command, CommandQueue, Commands},
world::World,
};
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand::{rngs::SmallRng, RngCore, SeedableRng};

criterion_group!(benches, empty_cmds, cmds, rng_cmds);
criterion_group!(benches, empty_commands, spawn_commands, fake_commands);
criterion_main!(benches);

struct A;
struct B;
struct C;

fn empty_cmds(criterion: &mut Criterion) {
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(5));
group.measurement_time(std::time::Duration::from_secs(4));

group.bench_function("0_entities", |bencher| {
let mut world = World::default();
Expand All @@ -29,34 +29,10 @@ fn empty_cmds(criterion: &mut Criterion) {
group.finish();
}

fn cmds(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("commands");
fn spawn_commands(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("spawn_commands");
group.warm_up_time(std::time::Duration::from_millis(500));
group.measurement_time(std::time::Duration::from_secs(5));

for entity_count in (1..5).map(|i| i * 2 * 1000) {
group.bench_function(format!("{}_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_cmds(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("rng_commands");
group.warm_up_time(std::time::Duration::from_millis(500));
group.measurement_time(std::time::Duration::from_secs(5));
group.measurement_time(std::time::Duration::from_secs(4));

for entity_count in (1..5).map(|i| i * 2 * 1000) {
group.bench_function(format!("{}_entities", entity_count), |bencher| {
Expand Down Expand Up @@ -95,3 +71,35 @@ fn rng_cmds(criterion: &mut Criterion) {

group.finish();
}

struct FakeCommand;

impl Command for FakeCommand {
fn write(self, world: &mut World) {
black_box(world);
}
}

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

for command_count in (1..5).map(|i| i * 2 * 1000) {
group.bench_function(format!("{}_commands", 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..command_count {
commands.add(FakeCommand);
}
drop(commands);
command_queue.apply(&mut world);
});
});
}

group.finish();
}

0 comments on commit 77a777f

Please sign in to comment.