-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
iter_frag_foreach_wide_sparse.rs
83 lines (77 loc) · 2.48 KB
/
iter_frag_foreach_wide_sparse.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use bevy_ecs::prelude::*;
macro_rules! create_entities {
($world:ident; $( $variants:ident ),*) => {
$(
#[derive(Component)]
struct $variants(f32);
for _ in 0..5 {
$world.spawn($variants(0.0));
}
)*
};
}
#[derive(Component)]
struct Data<const X: usize>(f32);
pub struct Benchmark<'w>(
World,
QueryState<(
&'w mut Data<0>,
&'w mut Data<1>,
&'w mut Data<2>,
&'w mut Data<3>,
&'w mut Data<4>,
&'w mut Data<5>,
&'w mut Data<6>,
&'w mut Data<7>,
&'w mut Data<8>,
&'w mut Data<9>,
&'w mut Data<10>,
)>,
);
impl<'w> Benchmark<'w> {
pub fn new() -> Self {
let mut world = World::new();
for _ in 0..5 {
world.spawn((
Data::<0>(1.0),
Data::<1>(1.0),
Data::<2>(1.0),
Data::<3>(1.0),
Data::<4>(1.0),
Data::<5>(1.0),
Data::<6>(1.0),
Data::<7>(1.0),
Data::<8>(1.0),
Data::<9>(1.0),
Data::<10>(1.0),
));
}
create_entities!(world; C00, C01, C02, C03, C04, C05, C06, C07, C08, C09);
create_entities!(world; C10, C11, C12, C13, C14, C15, C16, C17, C18, C19);
create_entities!(world; C20, C21, C22, C23, C24, C25, C26, C27, C28, C29);
create_entities!(world; C30, C31, C32, C33, C34, C35, C36, C37, C38, C39);
create_entities!(world; C40, C41, C42, C43, C44, C45, C46, C47, C48, C49);
create_entities!(world; C50, C51, C52, C53, C54, C55, C56, C57, C58, C59);
create_entities!(world; C60, C61, C62, C63, C64, C65, C66, C67, C68, C69);
create_entities!(world; C70, C71, C72, C73, C74, C75, C76, C77, C78, C79);
create_entities!(world; C80, C81, C82, C83, C84, C85, C86, C87, C88, C89);
create_entities!(world; C90, C91, C92, C93, C94, C95, C96, C97, C98, C99);
let query = world.query();
Self(world, query)
}
pub fn run(&mut self) {
self.1.for_each_mut(&mut self.0, |mut data| {
data.0 .0 *= 2.0;
data.1 .0 *= 2.0;
data.2 .0 *= 2.0;
data.3 .0 *= 2.0;
data.4 .0 *= 2.0;
data.5 .0 *= 2.0;
data.6 .0 *= 2.0;
data.7 .0 *= 2.0;
data.8 .0 *= 2.0;
data.9 .0 *= 2.0;
data.10 .0 *= 2.0;
});
}
}