Skip to content

Commit 537a638

Browse files
committed
feat: add full system update
1 parent 5ca9a89 commit 537a638

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

benches/particle_simulation.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ fn aos_apply_gravity(c: &mut Criterion) {
3535
});
3636
}
3737

38+
fn aos_full_update(c: &mut Criterion) {
39+
c.bench_function("aos_full_update", |b| {
40+
let mut system = aos::ParticleSystem::new(MEDIUM);
41+
let gravity = Vec3::new(0.0, -9.81, 0.0);
42+
let dt = 0.016;
43+
b.iter(|| {
44+
black_box(system.update(black_box(gravity), black_box(dt)));
45+
});
46+
});
47+
}
48+
3849
// ============================================================================
3950
// Structure of Arrays - Cache Friendly
4051
// ============================================================================
@@ -67,13 +78,26 @@ fn soa_apply_gravity(c: &mut Criterion) {
6778
});
6879
}
6980

81+
fn soa_full_update(c: &mut Criterion) {
82+
c.bench_function("soa_full_update", |b| {
83+
let mut system = soa::ParticleSystem::new(MEDIUM);
84+
let gravity = Vec3::new(0.0, -9.81, 0.0);
85+
let dt = 0.016;
86+
b.iter(|| {
87+
black_box(system.update(black_box(gravity), black_box(dt)));
88+
});
89+
});
90+
}
91+
7092
criterion_group!(
7193
benches,
7294
aos_update_positions,
7395
aos_kinetic_energy,
7496
aos_apply_gravity,
97+
aos_full_update,
7598
soa_update_positions,
7699
soa_kinetic_energy,
77-
soa_apply_gravity
100+
soa_apply_gravity,
101+
soa_full_update
78102
);
79103
criterion_main!(benches);

src/aos.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,13 @@ impl ParticleSystem {
7171
particle.velocity = particle.velocity.add(&gravity.scale(dt));
7272
}
7373
}
74+
75+
/// Full simulation update: apply forces, update positions, and compute energy
76+
/// This simulates a typical physics frame with multiple passes over the data
77+
#[inline(never)]
78+
pub fn update(&mut self, gravity: Vec3, dt: f32) -> f32 {
79+
self.apply_gravity(gravity, dt);
80+
self.update_positions(dt);
81+
self.compute_kinetic_energy()
82+
}
7483
}

src/soa.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,13 @@ impl ParticleSystem {
6161
*velocity = velocity.add(&gravity.scale(dt));
6262
}
6363
}
64+
65+
/// Full simulation update: apply forces, update positions, and compute energy
66+
/// This simulates a typical physics frame with multiple passes over the data
67+
#[inline(never)]
68+
pub fn update(&mut self, gravity: Vec3, dt: f32) -> f32 {
69+
self.apply_gravity(gravity, dt);
70+
self.update_positions(dt);
71+
self.compute_kinetic_energy()
72+
}
6473
}

0 commit comments

Comments
 (0)