From bbcdc6f2366505c62dd96fa835d5438cb607a912 Mon Sep 17 00:00:00 2001 From: NathanW Date: Mon, 14 Jun 2021 17:27:56 -0600 Subject: [PATCH] add fake commands --- benches/benches/bevy_ecs/commands.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/benches/benches/bevy_ecs/commands.rs b/benches/benches/bevy_ecs/commands.rs index 33edf6704759b4..ecfc98dcf7654c 100644 --- a/benches/benches/bevy_ecs/commands.rs +++ b/benches/benches/bevy_ecs/commands.rs @@ -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, world: &mut World) { + black_box(self); + black_box(world); + } +} + +impl Command for FakeCommandB { fn write(self: Box, world: &mut World) { black_box(self); black_box(world); @@ -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);