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

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