Skip to content

Commit

Permalink
Use batched par iter for hecs and bevy
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGillen committed Aug 20, 2020
1 parent a05bfd6 commit 377e96e
Show file tree
Hide file tree
Showing 10 changed files with 5,025 additions and 14 deletions.
21 changes: 14 additions & 7 deletions src/bevy/heavy_compute.rs
@@ -1,5 +1,6 @@
use bevy_ecs::prelude::*;
use cgmath::*;
use rayon::prelude::*;

#[derive(Copy, Clone)]
struct Position(Vector3<f32>);
Expand Down Expand Up @@ -29,12 +30,18 @@ impl Benchmark {
}

pub fn run(&mut self) {
for (mut pos, mut mat) in self.0.query::<(&mut Position, &mut Matrix4<f32>)>().iter() {
for _ in 0..100 {
*mat = mat.invert().unwrap();
}

pos.0 = mat.transform_vector(pos.0);
}
self.0
.query::<(&mut Position, &mut Matrix4<f32>)>()
.iter_batched(64)
.par_bridge()
.for_each(|batch| {
for (mut pos, mut mat) in batch {
for _ in 0..100 {
*mat = mat.invert().unwrap();
}

pos.0 = mat.transform_vector(pos.0);
}
});
}
}
21 changes: 14 additions & 7 deletions src/hecs/heavy_compute.rs
@@ -1,5 +1,6 @@
use cgmath::*;
use hecs::*;
use rayon::prelude::*;

#[derive(Copy, Clone)]
struct Position(Vector3<f32>);
Expand Down Expand Up @@ -29,12 +30,18 @@ impl Benchmark {
}

pub fn run(&mut self) {
for (_, (mut pos, mat)) in self.0.query::<(&mut Position, &mut Matrix4<f32>)>().iter() {
for _ in 0..100 {
*mat = mat.invert().unwrap();
}

pos.0 = mat.transform_vector(pos.0);
}
self.0
.query::<(&mut Position, &mut Matrix4<f32>)>()
.iter_batched(64)
.par_bridge()
.for_each(|batch| {
for (_, (mut pos, mat)) in batch {
for _ in 0..100 {
*mat = mat.invert().unwrap();
}

pos.0 = mat.transform_vector(pos.0);
}
});
}
}
@@ -0,0 +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}}
1,188 changes: 1,188 additions & 0 deletions target/criterion/add_remove_component/specs/report/both/pdf.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
314 changes: 314 additions & 0 deletions target/criterion/add_remove_component/specs/report/both/regression.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
668 changes: 668 additions & 0 deletions target/criterion/add_remove_component/specs/report/change/mean.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
668 changes: 668 additions & 0 deletions target/criterion/add_remove_component/specs/report/change/median.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
694 changes: 694 additions & 0 deletions target/criterion/add_remove_component/specs/report/change/t-test.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,163 changes: 1,163 additions & 0 deletions target/criterion/add_remove_component/specs/report/relative_pdf_small.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 377e96e

Please sign in to comment.