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

Commit 377e96e

Browse files
committed
Use batched par iter for hecs and bevy
1 parent a05bfd6 commit 377e96e

File tree

10 files changed

+5025
-14
lines changed

10 files changed

+5025
-14
lines changed

src/bevy/heavy_compute.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use bevy_ecs::prelude::*;
22
use cgmath::*;
3+
use rayon::prelude::*;
34

45
#[derive(Copy, Clone)]
56
struct Position(Vector3<f32>);
@@ -29,12 +30,18 @@ impl Benchmark {
2930
}
3031

3132
pub fn run(&mut self) {
32-
for (mut pos, mut mat) in self.0.query::<(&mut Position, &mut Matrix4<f32>)>().iter() {
33-
for _ in 0..100 {
34-
*mat = mat.invert().unwrap();
35-
}
36-
37-
pos.0 = mat.transform_vector(pos.0);
38-
}
33+
self.0
34+
.query::<(&mut Position, &mut Matrix4<f32>)>()
35+
.iter_batched(64)
36+
.par_bridge()
37+
.for_each(|batch| {
38+
for (mut pos, mut mat) in batch {
39+
for _ in 0..100 {
40+
*mat = mat.invert().unwrap();
41+
}
42+
43+
pos.0 = mat.transform_vector(pos.0);
44+
}
45+
});
3946
}
4047
}

src/hecs/heavy_compute.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use cgmath::*;
22
use hecs::*;
3+
use rayon::prelude::*;
34

45
#[derive(Copy, Clone)]
56
struct Position(Vector3<f32>);
@@ -29,12 +30,18 @@ impl Benchmark {
2930
}
3031

3132
pub fn run(&mut self) {
32-
for (_, (mut pos, mat)) in self.0.query::<(&mut Position, &mut Matrix4<f32>)>().iter() {
33-
for _ in 0..100 {
34-
*mat = mat.invert().unwrap();
35-
}
36-
37-
pos.0 = mat.transform_vector(pos.0);
38-
}
33+
self.0
34+
.query::<(&mut Position, &mut Matrix4<f32>)>()
35+
.iter_batched(64)
36+
.par_bridge()
37+
.for_each(|batch| {
38+
for (_, (mut pos, mat)) in batch {
39+
for _ in 0..100 {
40+
*mat = mat.invert().unwrap();
41+
}
42+
43+
pos.0 = mat.transform_vector(pos.0);
44+
}
45+
});
3946
}
4047
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"mean":{"confidence_interval":{"confidence_level":0.95,"lower_bound":0.006564487351130271,"upper_bound":0.02767288517482775},"point_estimate":0.017190409920002203,"standard_error":0.005381268140474378},"median":{"confidence_interval":{"confidence_level":0.95,"lower_bound":0.0003467654342424896,"upper_bound":0.020996798836576087},"point_estimate":0.008700507276720337,"standard_error":0.005369756076431017}}

target/criterion/add_remove_component/specs/report/both/pdf.svg

Lines changed: 1188 additions & 0 deletions
Loading

target/criterion/add_remove_component/specs/report/both/regression.svg

Lines changed: 314 additions & 0 deletions
Loading

target/criterion/add_remove_component/specs/report/change/mean.svg

Lines changed: 668 additions & 0 deletions
Loading

target/criterion/add_remove_component/specs/report/change/median.svg

Lines changed: 668 additions & 0 deletions
Loading

target/criterion/add_remove_component/specs/report/change/t-test.svg

Lines changed: 694 additions & 0 deletions
Loading

target/criterion/add_remove_component/specs/report/relative_pdf_small.svg

Lines changed: 1163 additions & 0 deletions
Loading

target/criterion/add_remove_component/specs/report/relative_regression_small.svg

Lines changed: 301 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)