1use ponko_ecs::World;
4use std::hint::black_box;
5use std::time::Instant;
6
7struct Pos {
8 x: f32,
9 y: f32,
10}
11struct Vel {
12 x: f32,
13 y: f32,
14}
15
16fn main() {
17 let mut world = World::new();
18 world.spawn_batch((0..1_000_000).map(|_| (Pos { x: 0.0, y: 0.0 }, Vel { x: 1.0, y: 2.0 })));
19 let mut samples = Vec::with_capacity(200);
20 for i in 0..210 {
21 let start = Instant::now();
22 world.query::<(&mut Pos, &Vel)>().for_each(|(p, v)| {
23 p.x += v.x;
24 p.y += v.y;
25 });
26 black_box(&world);
27 let elapsed = start.elapsed().as_secs_f64() * 1000.0;
28 if i >= 10 {
29 samples.push(elapsed);
30 }
31 }
32 samples.sort_by(f64::total_cmp);
33 let checksum: f64 = world
34 .query::<&Pos>()
35 .iter()
36 .map(|p| f64::from(p.x) + f64::from(p.y))
37 .sum();
38 assert_eq!(checksum, 630_000_000.0);
39 println!(
40 "Rust: 1000000 entities, median {:.6} ms/update, checksum {checksum:.0}",
41 (samples[99] + samples[100]) / 2.0
42 );
43}