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.

48 lines
1.5 KiB

3 years ago
  1. use criterion::{BenchmarkId, measurement::Measurement};
  2. use criterion::{criterion_group, criterion_main, Criterion, Throughput, BenchmarkGroup};
  3. use gntag::agent::{Agent, SimpleAgent};
  4. use gntag::world::ActualWorld;
  5. fn world<M: Measurement>(mut group: BenchmarkGroup<M>, validate: bool) {
  6. let width: isize = 1000;
  7. for spacing in (50..100).step_by(10) {
  8. group.throughput(Throughput::Elements((width / spacing).pow(2) as u64));
  9. group.bench_with_input(
  10. BenchmarkId::from_parameter(spacing),
  11. &spacing,
  12. |b, &spacing| {
  13. let mut agents: Vec<(_, Box<dyn Agent>)> = vec![];
  14. for x in (0..width).step_by(spacing as usize) {
  15. for y in (0..width).step_by(spacing as usize) {
  16. agents.push(((x, y).into(), Box::new(SimpleAgent)));
  17. }
  18. }
  19. let mut world = ActualWorld::new((width, width).into(), agents, validate);
  20. b.iter(|| world.do_step());
  21. },
  22. );
  23. }
  24. group.finish();
  25. }
  26. fn world_validating(c: &mut Criterion) {
  27. let group = c.benchmark_group("world_validating");
  28. world(group, true)
  29. }
  30. fn world_nonvalidating(c: &mut Criterion) {
  31. let group = c.benchmark_group("world_nonvalidating");
  32. world(group, false)
  33. }
  34. criterion_group!(benches, world_validating, world_nonvalidating);
  35. criterion_main!(benches);
  36. // 5000/1000 -> 9,993
  37. // 5/01 -> 23,252
  38. // 50/10 -> 14,000
  39. // 100/20 -> 14,000
  40. // 100/10 -> 96,000
  41. // 100/05 -> 917,767
  42. // 200/10 -> 916,172
  43. // 1000/10 -> 443,482,526