-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
iter_frag_wide.rs
73 lines (66 loc) · 1.79 KB
/
iter_frag_wide.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
use bevy_ecs::prelude::*;
macro_rules! create_entities {
($world:ident; $( $variants:ident ),*) => {
$(
#[derive(Component)]
struct $variants(f32);
for _ in 0..20 {
$world.spawn((
$variants(0.0),
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),
));
}
)*
};
}
#[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();
create_entities!(world; A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z);
let query = world.query();
Self(world, query)
}
pub fn run(&mut self) {
for mut data in self.1.iter_mut(&mut self.0) {
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;
}
}
}