diff --git a/benches/benchmark.rs b/benches/benchmark.rs index ce51364..78d990e 100644 --- a/benches/benchmark.rs +++ b/benches/benchmark.rs @@ -1,16 +1,5 @@ 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)); - } - } - ActualWorld::new((width, width).into(), agents, validate) -} +use gntag::get_world; fn world(c: &mut Criterion) { let mut group = c.benchmark_group("world"); @@ -21,7 +10,7 @@ fn world(c: &mut Criterion) { BenchmarkId::new("validating", spacing), &spacing, |b, &spacing| { - let mut world = get_world(width, spacing as usize, true); + let mut world = get_world(width, width, spacing as usize, true); b.iter(|| world.do_step()); }, ); @@ -29,7 +18,7 @@ fn world(c: &mut Criterion) { BenchmarkId::new("non-validating", spacing), &spacing, |b, &spacing| { - let mut world = get_world(width, spacing as usize, false); + let mut world = get_world(width, width, spacing as usize, false); b.iter(|| world.do_step()); }, ); diff --git a/src/lib.rs b/src/lib.rs index 53a7904..486b5a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,16 @@ pub mod agent; pub mod view; pub mod world; + +use agent::{Agent, SimpleAgent}; +use world::ActualWorld; + +pub fn get_world(width: isize, height: isize, spacing: usize, validating: bool) -> ActualWorld { + let mut agents: Vec<(_, Box)> = vec![]; + for x in (0..width).step_by(spacing) { + for y in (0..height).step_by(spacing) { + agents.push(((x, y).into(), Box::new(SimpleAgent))); + } + } + ActualWorld::new((width, height).into(), agents, validating) +} diff --git a/src/main.rs b/src/main.rs index 8cb1afe..5f38ece 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ -use gntag::agent::{Agent, SimpleAgent}; +use gntag::get_world; use gntag::view::{Backend, TerminalView}; -use gntag::world::ActualWorld; use std::io; use std::io::Read; use std::process::exit; @@ -36,13 +35,7 @@ fn run_simulation(view: &Arc>>>) { .unwrap() .content_size() .unwrap(); - let mut agents: Vec<(_, Box)> = vec![]; - for x in (0..width).step_by(10) { - for y in (0..height).step_by(10) { - agents.push(((x, y).into(), Box::new(SimpleAgent))); - } - } - let mut world = ActualWorld::new((width, height).into(), agents, true); + let mut world = get_world(width, height, 10, true); let mut gen = 0; loop {