Share get_world
This commit is contained in:
parent
9b92497c3b
commit
1892f7e9f5
3 changed files with 18 additions and 23 deletions
|
|
@ -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<dyn Agent>));
|
||||
}
|
||||
}
|
||||
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());
|
||||
},
|
||||
);
|
||||
|
|
|
|||
13
src/lib.rs
13
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<dyn Agent>)> = 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)
|
||||
}
|
||||
|
|
|
|||
11
src/main.rs
11
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<Mutex<Option<TerminalView<impl Backend>>>>) {
|
|||
.unwrap()
|
||||
.content_size()
|
||||
.unwrap();
|
||||
let mut agents: Vec<(_, Box<dyn Agent>)> = 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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue