forked from bevyengine/bevy
/
add_remove_big_table.rs
54 lines (46 loc) · 1.32 KB
/
add_remove_big_table.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use bevy_ecs::prelude::*;
use glam::*;
#[derive(Component, Copy, Clone)]
struct A(Mat4);
#[derive(Component, Copy, Clone)]
struct B(Mat4);
#[derive(Component, Copy, Clone)]
struct C(Mat4);
#[derive(Component, Copy, Clone)]
struct D(Mat4);
#[derive(Component, Copy, Clone)]
struct E(Mat4);
#[derive(Component, Copy, Clone)]
struct F(Mat4);
pub struct Benchmark(World, Vec<Entity>);
impl Benchmark {
pub fn new() -> Self {
let mut world = World::default();
let mut entities = Vec::with_capacity(10_000);
for _ in 0..10_000 {
entities.push(
world
.spawn()
.insert_bundle((
A(Mat4::from_scale(Vec3::ONE)),
B(Mat4::from_scale(Vec3::ONE)),
C(Mat4::from_scale(Vec3::ONE)),
D(Mat4::from_scale(Vec3::ONE)),
E(Mat4::from_scale(Vec3::ONE)),
))
.id(),
);
}
Self(world, entities)
}
pub fn run(&mut self) {
for entity in &self.1 {
self.0
.entity_mut(*entity)
.insert(F(Mat4::from_scale(Vec3::ONE)));
}
for entity in &self.1 {
self.0.entity_mut(*entity).remove::<F>();
}
}
}