Skip to content

Commit

Permalink
add fake commands
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanSWard committed Jun 14, 2021
1 parent 5565020 commit bbcdc6f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions benches/benches/bevy_ecs/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,17 @@ fn spawn_commands(criterion: &mut Criterion) {
group.finish();
}

struct FakeCommand;
struct FakeCommandA;
struct FakeCommandB(u64);

impl Command for FakeCommand {
impl Command for FakeCommandA {
fn write(self: Box<Self>, world: &mut World) {
black_box(self);
black_box(world);
}
}

impl Command for FakeCommandB {
fn write(self: Box<Self>, world: &mut World) {
black_box(self);
black_box(world);
Expand All @@ -91,10 +99,17 @@ fn fake_commands(criterion: &mut Criterion) {
let mut world = World::default();
let mut command_queue = CommandQueue::default();

let mut rng = SmallRng::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..command_count {
commands.add(FakeCommand);
if rng_bool() {
commands.add(FakeCommandA);
} else {
commands.add(FakeCommandB(0));
}
}
drop(commands);
command_queue.apply(&mut world);
Expand Down

0 comments on commit bbcdc6f

Please sign in to comment.