Put different configurations together in benchmark
This commit is contained in:
parent
0ff0126c39
commit
637bec67f8
1 changed files with 25 additions and 23 deletions
|
|
@ -1,23 +1,35 @@
|
||||||
use criterion::{BenchmarkId, measurement::Measurement};
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
||||||
use criterion::{criterion_group, criterion_main, Criterion, Throughput, BenchmarkGroup};
|
|
||||||
use gntag::agent::{Agent, SimpleAgent};
|
use gntag::agent::{Agent, SimpleAgent};
|
||||||
use gntag::world::ActualWorld;
|
use gntag::world::ActualWorld;
|
||||||
|
|
||||||
fn world<M: Measurement>(mut group: BenchmarkGroup<M>, validate: bool) {
|
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;
|
let width: isize = 1000;
|
||||||
for spacing in (50..100).step_by(10) {
|
for spacing in (50..=100).step_by(25) {
|
||||||
group.throughput(Throughput::Elements((width / spacing).pow(2) as u64));
|
group.throughput(Throughput::Elements((width / spacing).pow(2) as u64));
|
||||||
group.bench_with_input(
|
group.bench_with_input(
|
||||||
BenchmarkId::from_parameter(spacing),
|
BenchmarkId::new("validating", spacing),
|
||||||
&spacing,
|
&spacing,
|
||||||
|b, &spacing| {
|
|b, &spacing| {
|
||||||
let mut agents: Vec<(_, Box<dyn Agent>)> = vec![];
|
let mut world = get_world(width, spacing as usize, true);
|
||||||
for x in (0..width).step_by(spacing as usize) {
|
b.iter(|| world.do_step());
|
||||||
for y in (0..width).step_by(spacing as usize) {
|
},
|
||||||
agents.push(((x, y).into(), Box::new(SimpleAgent)));
|
);
|
||||||
}
|
group.bench_with_input(
|
||||||
}
|
BenchmarkId::new("non-validating", spacing),
|
||||||
let mut world = ActualWorld::new((width, width).into(), agents, validate);
|
&spacing,
|
||||||
|
|b, &spacing| {
|
||||||
|
let mut world = get_world(width, spacing as usize, false);
|
||||||
b.iter(|| world.do_step());
|
b.iter(|| world.do_step());
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -25,17 +37,7 @@ fn world<M: Measurement>(mut group: BenchmarkGroup<M>, validate: bool) {
|
||||||
group.finish();
|
group.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn world_validating(c: &mut Criterion) {
|
criterion_group!(benches, world);
|
||||||
let group = c.benchmark_group("world_validating");
|
|
||||||
world(group, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn world_nonvalidating(c: &mut Criterion) {
|
|
||||||
let group = c.benchmark_group("world_nonvalidating");
|
|
||||||
world(group, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
criterion_group!(benches, world_validating, world_nonvalidating);
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
|
|
||||||
// 5000/1000 -> 9,993
|
// 5000/1000 -> 9,993
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue