use criterion::{BenchmarkId, measurement::Measurement}; use criterion::{criterion_group, criterion_main, Criterion, Throughput, BenchmarkGroup}; use gntag::agent::{Agent, SimpleAgent}; use gntag::world::ActualWorld; fn world(mut group: BenchmarkGroup, validate: bool) { let width: isize = 1000; for spacing in (50..100).step_by(10) { group.throughput(Throughput::Elements((width / spacing).pow(2) as u64)); group.bench_with_input( BenchmarkId::from_parameter(spacing), &spacing, |b, &spacing| { let mut agents: Vec<(_, Box)> = vec![]; for x in (0..width).step_by(spacing as usize) { for y in (0..width).step_by(spacing as usize) { agents.push(((x, y).into(), Box::new(SimpleAgent))); } } let mut world = ActualWorld::new((width, width).into(), agents, validate); b.iter(|| world.do_step()); }, ); } group.finish(); } fn world_validating(c: &mut Criterion) { let group = c.benchmark_group("world_validating"); world(group, true) } fn world_nonvalidating(c: &mut Criterion) { let group = c.benchmark_group("world_nonvalidating"); world(group, false) } criterion_group!(benches, world_validating, world_nonvalidating); criterion_main!(benches); // 5000/1000 -> 9,993 // 5/01 -> 23,252 // 50/10 -> 14,000 // 100/20 -> 14,000 // 100/10 -> 96,000 // 100/05 -> 917,767 // 200/10 -> 916,172 // 1000/10 -> 443,482,526