split benches

This commit is contained in:
Magnus Ulimoen 2020-01-27 21:00:44 +01:00
parent bc62e0f189
commit eda4eb4904
4 changed files with 115 additions and 107 deletions

View File

@ -27,7 +27,11 @@ debug = true
criterion = "0.3.0"
[[bench]]
name = "bench"
name = "maxwell"
harness = false
[[bench]]
name = "euler"
harness = false
[profile.bench]

View File

@ -1,106 +0,0 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use maxwell::operators::{SbpOperator, Upwind4, UpwindOperator, SBP4};
use maxwell::{EulerSystem, System};
fn advance_system<SBP: SbpOperator>(universe: &mut System<SBP>, n: usize) {
for _ in 0..n {
universe.advance(0.01);
}
}
fn advance_system_upwind<UO: UpwindOperator>(universe: &mut System<UO>, n: usize) {
for _ in 0..n {
universe.advance_upwind(0.01);
}
}
fn performance_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("System");
group.sample_size(25);
let w = 40;
let h = 26;
let x = ndarray::Array2::from_shape_fn((h, w), |(_, i)| i as f32 / (w - 1) as f32);
let y = ndarray::Array2::from_shape_fn((h, w), |(j, _)| j as f32 / (h - 1) as f32);
let mut universe = System::<Upwind4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap());
group.bench_function("advance", |b| {
b.iter(|| {
universe.set_gaussian(0.5, 0.5);
advance_system(&mut universe, black_box(20))
})
});
let mut universe = System::<Upwind4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap());
group.bench_function("advance_upwind", |b| {
b.iter(|| {
universe.set_gaussian(0.5, 0.5);
advance_system_upwind(&mut universe, black_box(20))
})
});
let mut universe = System::<SBP4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap());
group.bench_function("advance_trad4", |b| {
b.iter(|| {
universe.set_gaussian(0.5, 0.5);
advance_system(&mut universe, black_box(20))
})
});
group.finish();
}
criterion_group!(benches, performance_benchmark);
fn advance_euler_system<SBP: SbpOperator>(universe: &mut EulerSystem<SBP>, n: usize) {
for _ in 0..n {
universe.advance(1.0 / 40.0 * 0.2);
}
}
fn advance_euler_system_upwind<UO: UpwindOperator>(universe: &mut EulerSystem<UO>, n: usize) {
for _ in 0..n {
universe.advance_upwind(1.0 / 40.0 * 0.2);
}
}
fn euler_performance_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("EulerSystem");
group.sample_size(25);
let w = 40;
let h = 26;
let x = ndarray::Array1::linspace(-10.0, 10.0, w);
let x = x.broadcast((h, w)).unwrap();
let y = ndarray::Array1::linspace(-10.0, 10.0, h);
let y = y.broadcast((w, h)).unwrap().reversed_axes();
let mut universe = EulerSystem::<Upwind4>::new(x.into_owned(), y.into_owned());
group.bench_function("advance_euler", |b| {
b.iter(|| {
universe.vortex(0.0, 0.0);
advance_euler_system(&mut universe, black_box(20))
})
});
let mut universe = EulerSystem::<Upwind4>::new(x.into_owned(), y.into_owned());
group.bench_function("advance_euler_upwind", |b| {
b.iter(|| {
universe.vortex(0.0, 0.0);
advance_euler_system_upwind(&mut universe, black_box(20))
})
});
let mut universe = EulerSystem::<SBP4>::new(x.into_owned(), y.into_owned());
group.bench_function("advance_euler_trad4", |b| {
b.iter(|| {
universe.vortex(0.0, 0.0);
advance_euler_system(&mut universe, black_box(20))
})
});
group.finish();
}
criterion_group!(euler_benches, euler_performance_benchmark);
criterion_main!(benches, euler_benches);

56
benches/euler.rs Normal file
View File

@ -0,0 +1,56 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use maxwell::operators::{SbpOperator, Upwind4, UpwindOperator, SBP4};
use maxwell::EulerSystem;
fn advance_system<SBP: SbpOperator>(universe: &mut EulerSystem<SBP>, n: usize) {
for _ in 0..n {
universe.advance(1.0 / 40.0 * 0.2);
}
}
fn advance_system_upwind<UO: UpwindOperator>(universe: &mut EulerSystem<UO>, n: usize) {
for _ in 0..n {
universe.advance_upwind(1.0 / 40.0 * 0.2);
}
}
fn performance_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("EulerSystem");
group.sample_size(25);
let w = 40;
let h = 26;
let x = ndarray::Array1::linspace(-10.0, 10.0, w);
let x = x.broadcast((h, w)).unwrap();
let y = ndarray::Array1::linspace(-10.0, 10.0, h);
let y = y.broadcast((w, h)).unwrap().reversed_axes();
let mut universe = EulerSystem::<Upwind4>::new(x.into_owned(), y.into_owned());
group.bench_function("advance", |b| {
b.iter(|| {
universe.vortex(0.0, 0.0);
advance_system(&mut universe, black_box(20))
})
});
let mut universe = EulerSystem::<Upwind4>::new(x.into_owned(), y.into_owned());
group.bench_function("advance_upwind", |b| {
b.iter(|| {
universe.vortex(0.0, 0.0);
advance_system_upwind(&mut universe, black_box(20))
})
});
let mut universe = EulerSystem::<SBP4>::new(x.into_owned(), y.into_owned());
group.bench_function("advance_trad4", |b| {
b.iter(|| {
universe.vortex(0.0, 0.0);
advance_system(&mut universe, black_box(20))
})
});
group.finish();
}
criterion_group!(benches, performance_benchmark);
criterion_main!(benches);

54
benches/maxwell.rs Normal file
View File

@ -0,0 +1,54 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use maxwell::operators::{SbpOperator, Upwind4, UpwindOperator, SBP4};
use maxwell::System;
fn advance_system<SBP: SbpOperator>(universe: &mut System<SBP>, n: usize) {
for _ in 0..n {
universe.advance(0.01);
}
}
fn advance_system_upwind<UO: UpwindOperator>(universe: &mut System<UO>, n: usize) {
for _ in 0..n {
universe.advance_upwind(0.01);
}
}
fn performance_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("System");
group.sample_size(25);
let w = 40;
let h = 26;
let x = ndarray::Array2::from_shape_fn((h, w), |(_, i)| i as f32 / (w - 1) as f32);
let y = ndarray::Array2::from_shape_fn((h, w), |(j, _)| j as f32 / (h - 1) as f32);
let mut universe = System::<Upwind4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap());
group.bench_function("advance", |b| {
b.iter(|| {
universe.set_gaussian(0.5, 0.5);
advance_system(&mut universe, black_box(20))
})
});
let mut universe = System::<Upwind4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap());
group.bench_function("advance_upwind", |b| {
b.iter(|| {
universe.set_gaussian(0.5, 0.5);
advance_system_upwind(&mut universe, black_box(20))
})
});
let mut universe = System::<SBP4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap());
group.bench_function("advance_trad4", |b| {
b.iter(|| {
universe.set_gaussian(0.5, 0.5);
advance_system(&mut universe, black_box(20))
})
});
group.finish();
}
criterion_group!(benches, performance_benchmark);
criterion_main!(benches);