From 3671ba5e1f7dc54d8231befce418ed777c67ef1c Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 21 Aug 2020 22:53:37 +0200 Subject: [PATCH] Add benching of matrix creation --- maxwell/benches/bench.rs | 43 ++++++++++++++++++++++++++++++++++++++++ maxwell/src/lib.rs | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/maxwell/benches/bench.rs b/maxwell/benches/bench.rs index b958307..7893ff3 100644 --- a/maxwell/benches/bench.rs +++ b/maxwell/benches/bench.rs @@ -69,5 +69,48 @@ fn performance_benchmark(c: &mut Criterion) { group.finish(); } +#[cfg(feature = "sparse")] +fn sparse_creation(c: &mut Criterion) { + let mut group = c.benchmark_group("MaxwellSystem"); + group.sample_size(25); + let w = 40; + let h = 26; + group.bench_function("create_rhs_trad4", |b| { + b.iter(|| { + let _matrix = maxwell::sparse::rhs_matrix(&SBP4, w, h); + }) + }); + group.bench_function("create_rhs_upwind4", |b| { + b.iter(|| { + let _matrix = maxwell::sparse::rhs_matrix(&sbp::operators::Upwind4, w, h); + }) + }); + group.bench_function("create_rhs_upwind9", |b| { + b.iter(|| { + let _matrix = maxwell::sparse::rhs_matrix(&sbp::operators::Upwind9, w, h); + }) + }); + + group.bench_function("create_rhs_upwind_upwind4", |b| { + b.iter(|| { + let _matrix = + maxwell::sparse::rhs_matrix_with_upwind_dissipation(&sbp::operators::Upwind4, w, h); + }) + }); + + group.bench_function("create_rhs_upwind_upwind9", |b| { + b.iter(|| { + let _matrix = + maxwell::sparse::rhs_matrix_with_upwind_dissipation(&sbp::operators::Upwind9, w, h); + }) + }); +} + +#[cfg(feature = "sparse")] +criterion_group!(sparse_create, sparse_creation); criterion_group!(benches, performance_benchmark); + +#[cfg(feature = "sparse")] +criterion_main!(benches, sparse_create); +#[cfg(not(feature = "sparse"))] criterion_main!(benches); diff --git a/maxwell/src/lib.rs b/maxwell/src/lib.rs index d576145..c0988ee 100644 --- a/maxwell/src/lib.rs +++ b/maxwell/src/lib.rs @@ -6,7 +6,7 @@ use sbp::operators::{SbpOperator2d, UpwindOperator2d}; use sbp::Float; #[cfg(feature = "sparse")] -mod sparse; +pub mod sparse; #[derive(Clone, Debug)] pub struct Field(pub(crate) Array3);