Get benchmarks running again.

This commit is contained in:
2018-02-06 12:13:35 +01:00
parent 9e685d2027
commit 849c0aacb0

View File

@@ -63,19 +63,28 @@ impl Individual for Parabole {
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("calculate", move |b| {
let initial = (0..1000)
.map(|i| Parabole { x: i as f64 })
.map(|i| Parabole { x: f64::from(i) })
.collect::<Vec<_>>();
let mut simulation = Simulation::with_population(initial);
b.iter(|| {
simulation.calculate();
});
});
c.bench_function("evolve", move |b| {
let initial = (0..1000)
.map(|i| Parabole { x: f64::from(i) })
.collect::<Vec<_>>();
let population_size = initial.len();
let mut simulation = Simulation::with_population(initial);
c.bench_function("calculate", |b| b.iter(|| {
simulation.calculate();
}));
c.bench_function("evolve", |b| b.iter(|| {
b.iter(|| {
simulation.evolve(|parents, population| {
// Mate top 10 to get 5 children.
parents
@@ -120,7 +129,8 @@ fn criterion_benchmark(c: &mut Criterion) {
});
simulation.population.truncate(population_size);
}));
});
});
}
criterion_group!(benches, criterion_benchmark);