A simple actor-based simulation of tag, implemented in rust.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4 KiB

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use gntag::agent::{Agent, SimpleAgent};
use gntag::world::ActualWorld;
fn get_world(width: isize, spacing: usize, validate: bool) -> ActualWorld {
let mut agents = vec![];
for x in (0..width).step_by(spacing) {
for y in (0..width).step_by(spacing) {
agents.push(((x, y).into(), Box::new(SimpleAgent) as Box<dyn Agent>));
}
}
ActualWorld::new((width, width).into(), agents, validate)
}
fn world(c: &mut Criterion) {
let mut group = c.benchmark_group("world");
let width: isize = 1000;
for spacing in (50..=100).step_by(25) {
group.throughput(Throughput::Elements((width / spacing).pow(2) as u64));
group.bench_with_input(
BenchmarkId::new("validating", spacing),
&spacing,
|b, &spacing| {
let mut world = get_world(width, spacing as usize, true);
b.iter(|| world.do_step());
},
);
group.bench_with_input(
BenchmarkId::new("non-validating", spacing),
&spacing,
|b, &spacing| {
let mut world = get_world(width, spacing as usize, false);
b.iter(|| world.do_step());
},
);
}
group.finish();
}
criterion_group!(benches, world);
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