Last active
August 15, 2024 16:14
-
-
Save SanderMertens/b98ea829a1477f9b8620dd5878f707a3 to your computer and use it in GitHub Desktop.
Bevy benchmark
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
use bevy_ecs::prelude::*; | |
use bevy_hierarchy::*; | |
use bevy_ecs::world::CommandQueue; | |
use std::hint::black_box; | |
use rand; | |
use std::time::{Instant}; | |
#[derive(Component)] | |
struct C1(f32); | |
#[derive(Component)] | |
struct C2(f32); | |
#[derive(Component)] | |
struct C3(f32); | |
#[derive(Component)] | |
struct C4(f32); | |
#[derive(Component)] | |
struct C5(f32); | |
#[derive(Component)] | |
struct C6(f32); | |
#[derive(Component)] | |
struct C7(f32); | |
#[derive(Component)] | |
struct C8(f32); | |
#[derive(Component)] | |
struct C9(f32); | |
#[derive(Component)] | |
struct C10(f32); | |
#[derive(Component)] | |
struct C11(f32); | |
#[derive(Component)] | |
struct C12(f32); | |
#[derive(Component)] | |
struct C13(f32); | |
#[derive(Component)] | |
struct C14(f32); | |
#[derive(Component)] | |
struct C15(f32); | |
#[derive(Component)] | |
struct C16(f32); | |
#[derive(Component)] | |
struct C17(f32); | |
#[derive(Component)] | |
struct C18(f32); | |
#[derive(Component)] | |
struct C19(f32); | |
#[derive(Component)] | |
struct C20(f32); | |
#[derive(Component)] | |
struct C21(f32); | |
#[derive(Component)] | |
struct C22(f32); | |
#[derive(Component)] | |
struct C23(f32); | |
#[derive(Component)] | |
struct C24(f32); | |
#[derive(Component)] | |
struct C25(f32); | |
#[derive(Component)] | |
struct C26(f32); | |
#[derive(Component)] | |
struct C27(f32); | |
#[derive(Component)] | |
struct C28(f32); | |
#[derive(Component)] | |
struct C29(f32); | |
#[derive(Component)] | |
struct C30(f32); | |
#[derive(Component)] | |
struct C31(f32); | |
#[derive(Component)] | |
struct C32(f32); | |
#[derive(Component)] | |
struct T1(); | |
#[derive(Component)] | |
struct T2(); | |
#[derive(Component)] | |
struct T3(); | |
#[derive(Component)] | |
struct T4(); | |
#[derive(Component)] | |
struct T5(); | |
#[derive(Component)] | |
struct T6(); | |
#[derive(Component)] | |
struct T7(); | |
#[derive(Component)] | |
struct T8(); | |
#[derive(Component)] | |
struct T9(); | |
#[derive(Component)] | |
struct T10(); | |
#[derive(Component)] | |
struct T11(); | |
#[derive(Component)] | |
struct T12(); | |
#[derive(Component)] | |
struct T13(); | |
#[derive(Component)] | |
struct T14(); | |
#[derive(Component)] | |
struct T15(); | |
#[derive(Component)] | |
struct T16(); | |
#[derive(Component)] | |
struct T17(); | |
#[derive(Component)] | |
struct T18(); | |
#[derive(Component)] | |
struct T19(); | |
#[derive(Component)] | |
struct T20(); | |
#[derive(Component)] | |
struct T21(); | |
#[derive(Component)] | |
struct T22(); | |
#[derive(Component)] | |
struct T23(); | |
#[derive(Component)] | |
struct T24(); | |
#[derive(Component)] | |
struct T25(); | |
#[derive(Component)] | |
struct T26(); | |
#[derive(Component)] | |
struct T27(); | |
#[derive(Component)] | |
struct T28(); | |
#[derive(Component)] | |
struct T29(); | |
#[derive(Component)] | |
struct T30(); | |
#[derive(Component)] | |
struct T31(); | |
#[derive(Component)] | |
struct T32(); | |
fn print_result(name : &str, duration : std::time::Duration, count : u32) { | |
let mut duration = duration.as_nanos() as f64; | |
duration /= count as f64; | |
println!("{} {:.2}", name, duration); | |
} | |
fn get_empty() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let _ = world.get::<C1>(*e); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_get_empty", start.elapsed(), | |
count * entities.len() as u32); | |
} | |
fn get_not_found() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn(C1(0.0)).id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let _ = world.get::<C2>(*e); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_get_not_found", start.elapsed(), | |
count * entities.len() as u32); | |
} | |
fn get_1() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn(C1(0.0)).id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let _ = world.get::<C1>(*e); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_get_1", start.elapsed(), | |
count * entities.len() as u32); | |
} | |
fn add_remove_1_tags() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
emut.insert(T1()); | |
emut.remove::<T1>(); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_add_remove_1_tag", start.elapsed(), | |
2 * count * entities.len() as u32); | |
} | |
fn add_remove_2_tags() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
emut.insert(T1()); | |
emut.insert(T2()); | |
emut.remove::<T1>(); | |
emut.remove::<T2>(); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_add_remove_2_tags", start.elapsed(), | |
4 * count * entities.len() as u32); | |
} | |
fn add_remove_16_tags() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
emut.insert(T1()); | |
emut.insert(T2()); | |
emut.insert(T3()); | |
emut.insert(T4()); | |
emut.insert(T5()); | |
emut.insert(T6()); | |
emut.insert(T7()); | |
emut.insert(T8()); | |
emut.insert(T9()); | |
emut.insert(T10()); | |
emut.insert(T11()); | |
emut.insert(T12()); | |
emut.insert(T13()); | |
emut.insert(T14()); | |
emut.insert(T15()); | |
emut.insert(T16()); | |
emut.remove::<T1>(); | |
emut.remove::<T2>(); | |
emut.remove::<T3>(); | |
emut.remove::<T4>(); | |
emut.remove::<T5>(); | |
emut.remove::<T6>(); | |
emut.remove::<T7>(); | |
emut.remove::<T8>(); | |
emut.remove::<T9>(); | |
emut.remove::<T10>(); | |
emut.remove::<T11>(); | |
emut.remove::<T12>(); | |
emut.remove::<T13>(); | |
emut.remove::<T14>(); | |
emut.remove::<T15>(); | |
emut.remove::<T16>(); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_add_remove_16_tags", start.elapsed(), | |
32 * count * entities.len() as u32); | |
} | |
fn add_remove_32_tags() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
emut.insert(T1()); | |
emut.insert(T2()); | |
emut.insert(T3()); | |
emut.insert(T4()); | |
emut.insert(T5()); | |
emut.insert(T6()); | |
emut.insert(T7()); | |
emut.insert(T8()); | |
emut.insert(T9()); | |
emut.insert(T10()); | |
emut.insert(T11()); | |
emut.insert(T12()); | |
emut.insert(T13()); | |
emut.insert(T14()); | |
emut.insert(T15()); | |
emut.insert(T16()); | |
emut.insert(T17()); | |
emut.insert(T18()); | |
emut.insert(T19()); | |
emut.insert(T20()); | |
emut.insert(T21()); | |
emut.insert(T22()); | |
emut.insert(T23()); | |
emut.insert(T24()); | |
emut.insert(T25()); | |
emut.insert(T26()); | |
emut.insert(T27()); | |
emut.insert(T28()); | |
emut.insert(T29()); | |
emut.insert(T30()); | |
emut.insert(T31()); | |
emut.insert(T32()); | |
emut.remove::<T1>(); | |
emut.remove::<T2>(); | |
emut.remove::<T3>(); | |
emut.remove::<T4>(); | |
emut.remove::<T5>(); | |
emut.remove::<T6>(); | |
emut.remove::<T7>(); | |
emut.remove::<T8>(); | |
emut.remove::<T9>(); | |
emut.remove::<T10>(); | |
emut.remove::<T11>(); | |
emut.remove::<T12>(); | |
emut.remove::<T13>(); | |
emut.remove::<T14>(); | |
emut.remove::<T15>(); | |
emut.remove::<T16>(); | |
emut.remove::<T17>(); | |
emut.remove::<T18>(); | |
emut.remove::<T19>(); | |
emut.remove::<T20>(); | |
emut.remove::<T21>(); | |
emut.remove::<T22>(); | |
emut.remove::<T23>(); | |
emut.remove::<T24>(); | |
emut.remove::<T25>(); | |
emut.remove::<T26>(); | |
emut.remove::<T27>(); | |
emut.remove::<T28>(); | |
emut.remove::<T29>(); | |
emut.remove::<T30>(); | |
emut.remove::<T31>(); | |
emut.remove::<T32>(); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_add_remove_32_tags", start.elapsed(), | |
64 * count * entities.len() as u32); | |
} | |
fn add_remove_1_components() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
emut.insert(C1(0.0)); | |
emut.remove::<C1>(); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_add_remove_1_component", start.elapsed(), | |
2 * count * entities.len() as u32); | |
} | |
fn add_remove_2_components() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
emut.insert(C1(0.0)); | |
emut.insert(C2(0.0)); | |
emut.remove::<C1>(); | |
emut.remove::<C2>(); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_add_remove_2_components", start.elapsed(), | |
4 * count * entities.len() as u32); | |
} | |
fn add_remove_16_components() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
emut.insert(C1(0.0)); | |
emut.insert(C2(0.0)); | |
emut.insert(C3(0.0)); | |
emut.insert(C4(0.0)); | |
emut.insert(C5(0.0)); | |
emut.insert(C6(0.0)); | |
emut.insert(C7(0.0)); | |
emut.insert(C8(0.0)); | |
emut.insert(C9(0.0)); | |
emut.insert(C10(0.0)); | |
emut.insert(C11(0.0)); | |
emut.insert(C12(0.0)); | |
emut.insert(C13(0.0)); | |
emut.insert(C14(0.0)); | |
emut.insert(C15(0.0)); | |
emut.insert(C16(0.0)); | |
emut.remove::<C1>(); | |
emut.remove::<C2>(); | |
emut.remove::<C3>(); | |
emut.remove::<C4>(); | |
emut.remove::<C5>(); | |
emut.remove::<C6>(); | |
emut.remove::<C7>(); | |
emut.remove::<C8>(); | |
emut.remove::<C9>(); | |
emut.remove::<C10>(); | |
emut.remove::<C11>(); | |
emut.remove::<C12>(); | |
emut.remove::<C13>(); | |
emut.remove::<C14>(); | |
emut.remove::<C15>(); | |
emut.remove::<C16>(); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_add_remove_16_components", start.elapsed(), | |
32 * count * entities.len() as u32); | |
} | |
fn add_remove_32_components() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
emut.insert(C1(0.0)); | |
emut.insert(C2(0.0)); | |
emut.insert(C3(0.0)); | |
emut.insert(C4(0.0)); | |
emut.insert(C5(0.0)); | |
emut.insert(C6(0.0)); | |
emut.insert(C7(0.0)); | |
emut.insert(C8(0.0)); | |
emut.insert(C9(0.0)); | |
emut.insert(C10(0.0)); | |
emut.insert(C11(0.0)); | |
emut.insert(C12(0.0)); | |
emut.insert(C13(0.0)); | |
emut.insert(C14(0.0)); | |
emut.insert(C15(0.0)); | |
emut.insert(C16(0.0)); | |
emut.insert(C17(0.0)); | |
emut.insert(C18(0.0)); | |
emut.insert(C19(0.0)); | |
emut.insert(C20(0.0)); | |
emut.insert(C21(0.0)); | |
emut.insert(C22(0.0)); | |
emut.insert(C23(0.0)); | |
emut.insert(C24(0.0)); | |
emut.insert(C25(0.0)); | |
emut.insert(C26(0.0)); | |
emut.insert(C27(0.0)); | |
emut.insert(C28(0.0)); | |
emut.insert(C29(0.0)); | |
emut.insert(C30(0.0)); | |
emut.insert(C31(0.0)); | |
emut.insert(C32(0.0)); | |
emut.remove::<C1>(); | |
emut.remove::<C2>(); | |
emut.remove::<C3>(); | |
emut.remove::<C4>(); | |
emut.remove::<C5>(); | |
emut.remove::<C6>(); | |
emut.remove::<C7>(); | |
emut.remove::<C8>(); | |
emut.remove::<C9>(); | |
emut.remove::<C10>(); | |
emut.remove::<C11>(); | |
emut.remove::<C12>(); | |
emut.remove::<C13>(); | |
emut.remove::<C14>(); | |
emut.remove::<C15>(); | |
emut.remove::<C16>(); | |
emut.remove::<C17>(); | |
emut.remove::<C18>(); | |
emut.remove::<C19>(); | |
emut.remove::<C20>(); | |
emut.remove::<C21>(); | |
emut.remove::<C22>(); | |
emut.remove::<C23>(); | |
emut.remove::<C24>(); | |
emut.remove::<C25>(); | |
emut.remove::<C26>(); | |
emut.remove::<C27>(); | |
emut.remove::<C28>(); | |
emut.remove::<C29>(); | |
emut.remove::<C30>(); | |
emut.remove::<C31>(); | |
emut.remove::<C32>(); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_add_remove_32_components", start.elapsed(), | |
64 * count * entities.len() as u32); | |
} | |
fn add_existing_1_tag() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn(T1()).id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
emut.insert(T1()); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_add_existing_1_tag", start.elapsed(), | |
count * entities.len() as u32); | |
} | |
fn insert() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn(C1(0.0)).id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
emut.insert(T1()); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_insert", start.elapsed(), | |
count * entities.len() as u32); | |
} | |
fn get_mut() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn(C1(0.0)).id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let mut emut = world.entity_mut(*e); | |
let foo = emut.get_mut::<C1>(); | |
black_box(foo); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_get_mut", start.elapsed(), | |
count * entities.len() as u32); | |
} | |
fn get_mut_not_found() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn(C1(0.0)).id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
for e in &entities { | |
let _ = world.get_mut::<C2>(*e); | |
} | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_get_not_found", start.elapsed(), | |
count * entities.len() as u32); | |
} | |
fn add_remove_cmd_1_tags() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
let mut cmdqueue = CommandQueue::default(); | |
let mut cmds = Commands::new(&mut cmdqueue, &world); | |
for e in &entities { | |
let mut emut = cmds.entity(*e); | |
emut.insert(T1()); | |
emut.remove::<T1>(); | |
} | |
cmdqueue.apply(&mut world); | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_add_remove_cmd_1_tag", start.elapsed(), | |
2 * count * entities.len() as u32); | |
} | |
fn add_remove_cmd_16_tags() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
let mut cmdqueue = CommandQueue::default(); | |
let mut cmds = Commands::new(&mut cmdqueue, &world); | |
for e in &entities { | |
let mut emut = cmds.entity(*e); | |
emut.insert(T1()); | |
emut.insert(T2()); | |
emut.insert(T3()); | |
emut.insert(T4()); | |
emut.insert(T5()); | |
emut.insert(T6()); | |
emut.insert(T7()); | |
emut.insert(T8()); | |
emut.insert(T9()); | |
emut.insert(T10()); | |
emut.insert(T11()); | |
emut.insert(T12()); | |
emut.insert(T13()); | |
emut.insert(T14()); | |
emut.insert(T15()); | |
emut.insert(T16()); | |
emut.remove::<T1>(); | |
emut.remove::<T2>(); | |
emut.remove::<T3>(); | |
emut.remove::<T4>(); | |
emut.remove::<T5>(); | |
emut.remove::<T6>(); | |
emut.remove::<T7>(); | |
emut.remove::<T8>(); | |
emut.remove::<T9>(); | |
emut.remove::<T10>(); | |
emut.remove::<T11>(); | |
emut.remove::<T12>(); | |
emut.remove::<T13>(); | |
emut.remove::<T14>(); | |
emut.remove::<T15>(); | |
emut.remove::<T16>(); | |
} | |
cmdqueue.apply(&mut world); | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_cmd_add_remove_16_tags", start.elapsed(), | |
2 * 16 * count * entities.len() as u32); | |
} | |
fn add_remove_cmd_32_tags() { | |
let mut world = World::new(); | |
let mut entities = Vec::with_capacity(1000); | |
for _ in 0..1000 { | |
entities.push(world.spawn_empty().id()); | |
} | |
let start = Instant::now(); | |
let mut count = 0; | |
loop { | |
let mut cmdqueue = CommandQueue::default(); | |
let mut cmds = Commands::new(&mut cmdqueue, &world); | |
for e in &entities { | |
let mut emut = cmds.entity(*e); | |
emut.insert(T1()); | |
emut.insert(T2()); | |
emut.insert(T3()); | |
emut.insert(T4()); | |
emut.insert(T5()); | |
emut.insert(T6()); | |
emut.insert(T7()); | |
emut.insert(T8()); | |
emut.insert(T9()); | |
emut.insert(T10()); | |
emut.insert(T11()); | |
emut.insert(T12()); | |
emut.insert(T13()); | |
emut.insert(T14()); | |
emut.insert(T15()); | |
emut.insert(T16()); | |
emut.insert(T17()); | |
emut.insert(T18()); | |
emut.insert(T19()); | |
emut.insert(T20()); | |
emut.insert(T21()); | |
emut.insert(T22()); | |
emut.insert(T23()); | |
emut.insert(T24()); | |
emut.insert(T25()); | |
emut.insert(T26()); | |
emut.insert(T27()); | |
emut.insert(T28()); | |
emut.insert(T29()); | |
emut.insert(T30()); | |
emut.insert(T31()); | |
emut.insert(T32()); | |
emut.remove::<T1>(); | |
emut.remove::<T2>(); | |
emut.remove::<T3>(); | |
emut.remove::<T4>(); | |
emut.remove::<T5>(); | |
emut.remove::<T6>(); | |
emut.remove::<T7>(); | |
emut.remove::<T8>(); | |
emut.remove::<T9>(); | |
emut.remove::<T10>(); | |
emut.remove::<T11>(); | |
emut.remove::<T12>(); | |
emut.remove::<T13>(); | |
emut.remove::<T14>(); | |
emut.remove::<T15>(); | |
emut.remove::<T16>(); | |
emut.remove::<T17>(); | |
emut.remove::<T18>(); | |
emut.remove::<T19>(); | |
emut.remove::<T20>(); | |
emut.remove::<T21>(); | |
emut.remove::<T22>(); | |
emut.remove::<T23>(); | |
emut.remove::<T24>(); | |
emut.remove::<T25>(); | |
emut.remove::<T26>(); | |
emut.remove::<T27>(); | |
emut.remove::<T28>(); | |
emut.remove::<T29>(); | |
emut.remove::<T30>(); | |
emut.remove::<T31>(); | |
emut.remove::<T32>(); | |
} | |
cmdqueue.apply(&mut world); | |
count += 1; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
print_result("bevy_cmd_add_remove_32_tags", start.elapsed(), | |
2 * 32 * count * entities.len() as u32); | |
} | |
fn create_delete_empty() { | |
let mut world = World::new(); | |
let start = Instant::now(); | |
let mut count = 0; | |
let mut interval = 0; | |
loop { | |
let e = world.spawn_empty(); | |
e.despawn(); | |
count += 1; | |
interval += 1; | |
if interval == 25 { | |
interval = 0; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
} | |
print_result("bevy_create_delete_empty", start.elapsed(), | |
2 * count); | |
} | |
fn create_delete_tree(width : u32, depth : u32) { | |
let mut world = World::new(); | |
let start = Instant::now(); | |
let mut count = 0; | |
let mut interval = 0; | |
loop { | |
let root = world.spawn_empty().id(); | |
let mut cur = root; | |
for _ in 0..depth { | |
for _ in 0..width - 1 { | |
let child = world.spawn_empty().id(); | |
world.entity_mut(cur).add_child(child); | |
} | |
let child = world.spawn_empty().id(); | |
world.entity_mut(cur).add_child(child); | |
cur = child; | |
} | |
world.entity_mut(root).despawn_recursive(); | |
count += 1; | |
interval += 1; | |
if interval == 25 { | |
interval = 0; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
} | |
let mut duration = start.elapsed().as_nanos() as f64; | |
duration /= count as f64; | |
duration /= width as f64; | |
println!("bevy_create_delete_tree_w{:?}_d{:?} {:.2}", width, depth, duration); | |
} | |
fn flip_coin() -> bool { | |
rand::random::<bool>() | |
} | |
fn query_iter_1_table_1_tag() { | |
let mut world = World::new(); | |
for _ in 0..65536 { | |
let mut e = world.spawn_empty(); | |
e.insert(T1()); | |
} | |
let mut q = world.query::<(Entity, &T1)>(); | |
let mut result : u64 = 0; | |
let start = Instant::now(); | |
let mut count = 0; | |
let mut interval = 0; | |
loop { | |
for (e, _t1) in q.iter(&world) { | |
result += e.to_bits(); | |
} | |
count += 1; | |
interval += 1; | |
if interval == 25 { | |
interval = 0; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
} | |
print_result("bevy_query_iter_1_tag", start.elapsed(), | |
count); | |
println!("result {:?}", result); | |
} | |
fn query_foreach_1_table_1_tag() { | |
let mut world = World::new(); | |
for _ in 0..65536 { | |
let mut e = world.spawn_empty(); | |
e.insert(T1()); | |
} | |
let mut q = world.query::<(Entity, &T1)>(); | |
let mut result : u64 = 0; | |
let start = Instant::now(); | |
let mut count = 0; | |
let mut interval = 0; | |
loop { | |
q.iter(&world).for_each(|(e, _t1)| { | |
result += e.to_bits(); | |
}); | |
count += 1; | |
interval += 1; | |
if interval == 25 { | |
interval = 0; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
} | |
print_result("bevy_query_foreach_1_tag", start.elapsed(), | |
count); | |
println!("result {:?}", result); | |
} | |
fn query_iter_rnd_8_tags() { | |
let mut world = World::new(); | |
for _ in 0..65536 { | |
let mut e = world.spawn_empty(); | |
if flip_coin() { | |
e.insert(T2()); | |
} | |
if flip_coin() { | |
e.insert(T3()); | |
} | |
if flip_coin() { | |
e.insert(T4()); | |
} | |
if flip_coin() { | |
e.insert(T5()); | |
} | |
if flip_coin() { | |
e.insert(T6()); | |
} | |
if flip_coin() { | |
e.insert(T7()); | |
} | |
if flip_coin() { | |
e.insert(T8()); | |
} | |
if flip_coin() { | |
e.insert(T9()); | |
} | |
e.insert(T1()); | |
} | |
let mut q = world.query::<(Entity, &T1)>(); | |
let mut result : u64 = 0; | |
let start = Instant::now(); | |
let mut count = 0; | |
let mut interval = 0; | |
loop { | |
for (e, _t1) in q.iter(&world) { | |
result += e.to_bits(); | |
} | |
count += 1; | |
interval += 1; | |
if interval == 25 { | |
interval = 0; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
} | |
print_result("bevy_iter_rnd_8_tags", start.elapsed(), | |
count); | |
println!("result {:?}", result); | |
} | |
fn query_foreach_rnd_8_tags() { | |
let mut world = World::new(); | |
for _ in 0..65536 { | |
let mut e = world.spawn_empty(); | |
if flip_coin() { | |
e.insert(T2()); | |
} | |
if flip_coin() { | |
e.insert(T3()); | |
} | |
if flip_coin() { | |
e.insert(T4()); | |
} | |
if flip_coin() { | |
e.insert(T5()); | |
} | |
if flip_coin() { | |
e.insert(T6()); | |
} | |
if flip_coin() { | |
e.insert(T7()); | |
} | |
if flip_coin() { | |
e.insert(T8()); | |
} | |
e.insert(T1()); | |
} | |
let mut q = world.query::<(Entity, &T1)>(); | |
let mut result : u64 = 0; | |
let start = Instant::now(); | |
let mut count = 0; | |
let mut interval = 0; | |
loop { | |
q.iter(&world).for_each(|(e, _t1)| { | |
result += e.to_bits(); | |
}); | |
count += 1; | |
interval += 1; | |
if interval == 25 { | |
interval = 0; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
} | |
print_result("bevy_foreach_rnd_8_tags", start.elapsed(), | |
count); | |
println!("result {:?}", result); | |
} | |
fn query_foreach_255_empty_1_fill() { | |
let mut world = World::new(); | |
world.spawn_empty(); | |
for i in 0..65536 { | |
let mut e = world.spawn_empty(); | |
if flip_coin() { | |
e.insert(T2()); | |
} | |
if flip_coin() { | |
e.insert(T3()); | |
} | |
if flip_coin() { | |
e.insert(T4()); | |
} | |
if flip_coin() { | |
e.insert(T5()); | |
} | |
if flip_coin() { | |
e.insert(T6()); | |
} | |
if flip_coin() { | |
e.insert(T7()); | |
} | |
if flip_coin() { | |
e.insert(T8()); | |
} | |
e.insert(T1()); | |
if i != 0 { | |
e.despawn(); | |
} | |
} | |
let mut q = world.query::<(Entity, &T1)>(); | |
let mut result : u64 = 0; | |
let start = Instant::now(); | |
let mut count = 0; | |
let mut interval = 0; | |
loop { | |
q.iter(&world).for_each(|(e, _t1)| { | |
result += e.to_bits(); | |
}); | |
count += 1; | |
interval += 1; | |
if interval == 25 { | |
interval = 0; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
} | |
print_result("bevy_query_foreach_255_empty_1_fill", start.elapsed(), | |
count); | |
println!("result {:?}", result); | |
} | |
fn query_foreach_1023_empty_1_fill() { | |
let mut world = World::new(); | |
world.spawn_empty(); | |
for i in 0..65536 { | |
let mut e = world.spawn_empty(); | |
if flip_coin() { | |
e.insert(T2()); | |
} | |
if flip_coin() { | |
e.insert(T3()); | |
} | |
if flip_coin() { | |
e.insert(T4()); | |
} | |
if flip_coin() { | |
e.insert(T5()); | |
} | |
if flip_coin() { | |
e.insert(T6()); | |
} | |
if flip_coin() { | |
e.insert(T7()); | |
} | |
if flip_coin() { | |
e.insert(T8()); | |
} | |
if flip_coin() { | |
e.insert(T9()); | |
} | |
if flip_coin() { | |
e.insert(T10()); | |
} | |
e.insert(T1()); | |
if i != 0 { | |
e.despawn(); | |
} | |
} | |
let mut q = world.query::<(Entity, &T1)>(); | |
let mut result : u64 = 0; | |
let start = Instant::now(); | |
let mut count = 0; | |
let mut interval = 0; | |
loop { | |
q.iter(&world).for_each(|(e, _t1)| { | |
result += e.to_bits(); | |
}); | |
count += 1; | |
interval += 1; | |
if interval == 25 { | |
interval = 0; | |
let spent = start.elapsed(); | |
if spent.as_secs() >= 1 { | |
break; | |
} | |
} | |
} | |
print_result("bevy_query_foreach_1023_empty_1_fill", start.elapsed(), | |
count); | |
println!("result {:?}", result); | |
} | |
fn main() { | |
get_not_found(); | |
get_1(); | |
add_remove_1_tags(); | |
add_remove_2_tags(); | |
add_remove_16_tags(); | |
add_remove_32_tags(); | |
add_remove_1_components(); | |
add_remove_2_components(); | |
add_remove_16_components(); | |
add_remove_32_components(); | |
add_existing_1_tag(); | |
insert(); | |
get_mut(); | |
get_mut_not_found(); | |
add_remove_cmd_1_tags(); | |
add_remove_cmd_16_tags(); | |
add_remove_cmd_32_tags(); | |
create_delete_empty(); | |
create_delete_tree(1, 1); | |
create_delete_tree(1, 10); | |
create_delete_tree(1, 100); | |
create_delete_tree(1, 1000); | |
create_delete_tree(10, 1); | |
create_delete_tree(10, 10); | |
create_delete_tree(10, 100); | |
create_delete_tree(10, 1000); | |
create_delete_tree(100, 1); | |
create_delete_tree(100, 10); | |
create_delete_tree(100, 100); | |
create_delete_tree(100, 1000); | |
create_delete_tree(1000, 1); | |
create_delete_tree(1000, 10); | |
create_delete_tree(1000, 100); | |
create_delete_tree(1000, 1000); | |
query_iter_1_table_1_tag(); | |
query_foreach_1_table_1_tag(); | |
query_iter_rnd_8_tags(); | |
query_foreach_rnd_8_tags(); | |
query_foreach_255_empty_1_fill(); | |
query_foreach_1023_empty_1_fill(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment