Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit b459450

Browse files
authored
Merge pull request #8 from leudz/master
shipyard speed-ups
2 parents 414ae41 + 8dc734e commit b459450

File tree

6 files changed

+38
-31
lines changed

6 files changed

+38
-31
lines changed

src/shipyard/add_remove.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ impl Benchmark {
2222
}
2323

2424
pub fn run(&mut self) {
25-
for entity in &self.1 {
26-
self.0.run(|entities: EntitiesViewMut, mut b: ViewMut<B>| {
25+
self.0.run(|entities: EntitiesViewMut, mut b: ViewMut<B>| {
26+
for entity in &self.1 {
2727
entities.add_component(&mut b, B(0.0), *entity);
28-
});
29-
}
28+
}
29+
});
3030

31-
for entity in &self.1 {
32-
self.0.run(|mut b: ViewMut<B>| {
31+
self.0.run(|mut b: ViewMut<B>| {
32+
for entity in &self.1 {
3333
b.remove(*entity);
34-
});
35-
}
34+
}
35+
});
3636
}
3737
}

src/shipyard/frag_iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ impl Benchmark {
3434

3535
pub fn run(&mut self) {
3636
self.0.run(|mut data: ViewMut<Data>| {
37-
for data in (&mut data).iter() {
37+
(&mut data).iter().for_each(|data| {
3838
data.0 *= 2.0;
39-
}
39+
})
4040
});
4141
}
4242
}

src/shipyard/schedule.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ struct D(f32);
77
struct E(f32);
88

99
fn ab(mut a: ViewMut<A>, mut b: ViewMut<B>) {
10-
for (a, b) in (&mut a, &mut b).iter() {
10+
(&mut a, &mut b).iter().for_each(|(a, b)| {
1111
std::mem::swap(&mut a.0, &mut b.0);
12-
}
12+
})
1313
}
1414

1515
fn cd(mut c: ViewMut<C>, mut d: ViewMut<D>) {
16-
for (c, d) in (&mut c, &mut d).iter() {
16+
(&mut c, &mut d).iter().for_each(|(c, d)| {
1717
std::mem::swap(&mut c.0, &mut d.0);
18-
}
18+
})
1919
}
2020

2121
fn ce(mut c: ViewMut<C>, mut e: ViewMut<E>) {
22-
for (c, e) in (&mut c, &mut e).iter() {
22+
(&mut c, &mut e).iter().for_each(|(c, e)| {
2323
std::mem::swap(&mut c.0, &mut e.0);
24-
}
24+
})
2525
}
2626

2727
pub struct Benchmark(World);

src/shipyard/simple_iter.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ impl Benchmark {
5050
pub fn run(&mut self) {
5151
self.0.run(
5252
|velocities: View<Velocity>, mut positions: ViewMut<Position>| {
53-
for (velocity, position) in (&velocities, &mut positions).iter() {
54-
position.0 += velocity.0;
55-
}
53+
(&velocities, &mut positions)
54+
.iter()
55+
.for_each(|(velocity, position)| {
56+
position.0 += velocity.0;
57+
})
5658
},
5759
);
5860
}

src/shipyard_packed/schedule.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ struct D(f32);
77
struct E(f32);
88

99
fn ab(mut a: ViewMut<A>, mut b: ViewMut<B>) {
10-
for (a, b) in (&mut a, &mut b).iter() {
10+
(&mut a, &mut b).iter().for_each(|(a, b)| {
1111
std::mem::swap(&mut a.0, &mut b.0);
12-
}
12+
})
1313
}
1414

1515
fn cd(mut c: ViewMut<C>, mut d: ViewMut<D>) {
16-
for (c, d) in (&mut c, &mut d).iter() {
16+
(&mut c, &mut d).iter().for_each(|(c, d)| {
1717
std::mem::swap(&mut c.0, &mut d.0);
18-
}
18+
})
1919
}
2020

2121
fn ce(mut c: ViewMut<C>, mut e: ViewMut<E>) {
22-
for (c, e) in (&mut c, &mut e).iter() {
22+
(&mut c, &mut e).iter().for_each(|(c, e)| {
2323
std::mem::swap(&mut c.0, &mut e.0);
24-
}
24+
})
2525
}
2626

2727
pub struct Benchmark(World);
@@ -31,12 +31,15 @@ impl Benchmark {
3131
let world = World::default();
3232

3333
world.run(
34-
|mut a: ViewMut<A>, mut b: ViewMut<B>, mut c: ViewMut<C>, mut d: ViewMut<D>| {
34+
|mut a: ViewMut<A>,
35+
mut b: ViewMut<B>,
36+
mut c: ViewMut<C>,
37+
mut d: ViewMut<D>,
38+
mut e: ViewMut<E>| {
3539
(&mut a, &mut b).tight_pack();
3640
(&mut c, &mut d).tight_pack();
3741

38-
// following pack is mutually exclusive with (c, d)
39-
//(&mut c, &mut e).tight_pack();
42+
(&mut e, &mut c).loose_pack();
4043
},
4144
);
4245

src/shipyard_packed/simple_iter.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ impl Benchmark {
5252
pub fn run(&mut self) {
5353
self.0.run(
5454
|velocities: View<Velocity>, mut positions: ViewMut<Position>| {
55-
for (velocity, position) in (&velocities, &mut positions).iter() {
56-
position.0 += velocity.0;
57-
}
55+
(&velocities, &mut positions)
56+
.iter()
57+
.for_each(|(velocity, position)| {
58+
position.0 += velocity.0;
59+
})
5860
},
5961
);
6062
}

0 commit comments

Comments
 (0)