add iteration overhead benchmark
authoralfadur
Tue, 28 Mar 2023 17:53:30 +0300
changeset 15974 ccd458b08113
parent 15973 feb7a76915d2
child 15975 343b8819b051
add iteration overhead benchmark
rust/hwphysics/benches/ecs_bench.rs
--- a/rust/hwphysics/benches/ecs_bench.rs	Sun Mar 26 20:55:19 2023 +0300
+++ b/rust/hwphysics/benches/ecs_bench.rs	Tue Mar 28 17:53:30 2023 +0300
@@ -52,6 +52,31 @@
     });
 }
 
+pub fn component_multirun(c: &mut Criterion) {
+    for n in (16..=64).step_by(16) {
+        let mut manager = GearDataManager::new();
+
+        manager.register::<P>();
+        manager.register::<V>();
+
+        for i in 1..=(SIZE / n) {
+            let gear_id = GearId::new(i as u16).unwrap();
+            manager.add(gear_id, &P::default());
+            manager.add(gear_id, &V::default());
+        }
+
+        c.bench_function(&format!("component run {}", n), |b| {
+            b.iter(|| {
+                for i in 0..n {
+                    manager
+                        .iter()
+                        .run(|(p, v): (&mut P, &mut V)| v.velocity += black_box(p.position));
+                }
+            })
+        });
+    }
+}
+
 pub fn component_add_remove(c: &mut Criterion) {
     let mut manager = GearDataManager::new();
     let mut gears1 = vec![];
@@ -84,5 +109,5 @@
     });
 }
 
-criterion_group!(benches, array_run, component_run, component_add_remove);
+criterion_group!(benches, array_run, component_run, component_multirun, component_add_remove);
 criterion_main!(benches);