s/criterion/easybench/ for less weight

This commit is contained in:
Robert Jördens 2021-02-17 18:35:52 +01:00
parent 90ef0836af
commit 78e69b1707
3 changed files with 57 additions and 45 deletions

7
Cargo.lock generated
View File

@ -212,6 +212,7 @@ dependencies = [
name = "dsp" name = "dsp"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"easybench",
"generic-array 0.14.4", "generic-array 0.14.4",
"libm", "libm",
"miniconf", "miniconf",
@ -220,6 +221,12 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "easybench"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "355215cf95ddc4db0459d5313c9b146bedd43453305e3f0f1c4e8fde7f8d3884"
[[package]] [[package]]
name = "embedded-dma" name = "embedded-dma"
version = "0.1.2" version = "0.1.2"

View File

@ -14,7 +14,7 @@ git = "https://github.com/quartiq/miniconf.git"
branch = "rs/issue-21/terminal-array-elements" branch = "rs/issue-21/terminal-array-elements"
[dev-dependencies] [dev-dependencies]
# criterion = "0.3" easybench = "1.0"
rand = "0.8" rand = "0.8"
ndarray = "0.14" ndarray = "0.14"
@ -22,10 +22,5 @@ ndarray = "0.14"
name = "micro" name = "micro"
harness = false harness = false
# Note: Due to a dependency injection bug, criterion enables std-features for serde, which breaks
# testing. Patch serde to not use std dependencies.
[patch.crates-io]
serde = { version = "1.0", features = ["derive"], default-features = false }
[features] [features]
nightly = [] nightly = []

View File

@ -1,70 +1,80 @@
use core::f32::consts::PI; use core::f32::consts::PI;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use dsp::{atan2, cossin}; use dsp::{atan2, cossin};
use dsp::{iir, iir_int}; use dsp::{iir, iir_int};
use dsp::{pll::PLL, rpll::RPLL}; use dsp::{pll::PLL, rpll::RPLL};
use easybench::bench_env;
fn atan2_bench(c: &mut Criterion) { fn atan2_bench() {
let xi = (10 << 16) as i32; let xi = (10 << 16) as i32;
let xf = xi as f32 / i32::MAX as f32; let xf = xi as f32 / i32::MAX as f32;
let yi = (-26_328 << 16) as i32; let yi = (-26_328 << 16) as i32;
let yf = yi as f32 / i32::MAX as f32; let yf = yi as f32 / i32::MAX as f32;
c.bench_function("atan2(y, x)", |b| { println!(
b.iter(|| atan2(black_box(yi), black_box(xi))) "atan2(yi, xi): {}",
}); bench_env((yi, xi), |(yi, xi)| atan2(*yi, *xi))
c.bench_function("y.atan2(x)", |b| { );
b.iter(|| black_box(yf).atan2(black_box(xf))) println!(
}); "yf.atan2(xf): {}",
bench_env((yf, xf), |(yf, xf)| yf.atan2(*xf))
);
} }
fn cossin_bench(c: &mut Criterion) { fn cossin_bench() {
let zi = -0x7304_2531_i32; let zi = -0x7304_2531_i32;
let zf = zi as f32 / i32::MAX as f32 * PI; let zf = zi as f32 / i32::MAX as f32 * PI;
c.bench_function("cossin(zi)", |b| b.iter(|| cossin(black_box(zi)))); println!("cossin(zi): {}", bench_env(zi, |zi| cossin(*zi)));
c.bench_function("zf.sin_cos()", |b| b.iter(|| black_box(zf).sin_cos())); println!("zf.sin_cos(): {}", bench_env(zf, |zf| zf.sin_cos()));
} }
fn rpll_bench(c: &mut Criterion) { fn rpll_bench() {
let mut dut = RPLL::new(8); let mut dut = RPLL::new(8);
c.bench_function("RPLL::update(Some(t), 21, 20)", |b| { println!(
b.iter(|| dut.update(black_box(Some(0x241)), 21, 20)) "RPLL::update(Some(t), 21, 20): {}",
}); bench_env(Some(0x241), |x| dut.update(*x, 21, 20))
c.bench_function("RPLL::update(Some(t), sf, sp)", |b| { );
b.iter(|| { println!(
dut.update(black_box(Some(0x241)), black_box(21), black_box(20)) "RPLL::update(Some(t), sf, sp): {}",
}) bench_env((Some(0x241), 21, 20), |(x, p, q)| dut.update(*x, *p, *q))
}); );
} }
fn pll_bench(c: &mut Criterion) { fn pll_bench() {
let mut dut = PLL::default(); let mut dut = PLL::default();
c.bench_function("PLL::update(t, 12, 11)", |b| { println!(
b.iter(|| dut.update(black_box(0x1234), 12, 1)) "PLL::update(t, 12, 12): {}",
}); bench_env(0x241, |x| dut.update(*x, 12, 12))
c.bench_function("PLL::update(t, sf, sp)", |b| { );
b.iter(|| dut.update(black_box(0x241), black_box(21), black_box(20))) println!(
}); "PLL::update(t, sf, sp): {}",
bench_env((0x241, 21, 20), |(x, p, q)| dut.update(*x, *p, *q))
);
} }
fn iir_int_bench(c: &mut Criterion) { fn iir_int_bench() {
let dut = iir_int::IIR::default(); let dut = iir_int::IIR::default();
let mut xy = iir_int::Vec5::default(); let mut xy = iir_int::Vec5::default();
c.bench_function("int_iir::IIR::update(s, x)", |b| { println!(
b.iter(|| dut.update(&mut xy, black_box(0x2832))) "int_iir::IIR::update(s, x): {}",
}); bench_env(0x2832, |x| dut.update(&mut xy, *x))
);
} }
fn iir_bench(c: &mut Criterion) { fn iir_bench() {
let dut = iir::IIR::default(); let dut = iir::IIR::default();
let mut xy = iir::Vec5::default(); let mut xy = iir::Vec5::default();
c.bench_function("int::IIR::update(s, x)", |b| { println!(
b.iter(|| dut.update(&mut xy, black_box(0.32241))) "int::IIR::update(s, x): {}",
}); bench_env(0.32241, |x| dut.update(&mut xy, *x))
);
} }
criterion_group!(trig, atan2_bench, cossin_bench); fn main() {
criterion_group!(pll, rpll_bench, pll_bench); atan2_bench();
criterion_group!(iir, iir_int_bench, iir_bench); cossin_bench();
criterion_main!(trig, pll, iir); rpll_bench();
pll_bench();
iir_int_bench();
iir_bench();
}