pounder_test/dsp/benches/micro.rs

95 lines
2.2 KiB
Rust
Raw Normal View History

2021-02-01 01:54:09 +08:00
use core::f32::consts::PI;
2021-02-27 21:54:46 +08:00
2021-02-19 17:44:46 +08:00
use easybench::bench_env;
2021-02-27 21:54:46 +08:00
use generic_array::typenum::U4;
2021-02-27 22:02:16 +08:00
use dsp::{atan2, cossin, iir, iir_int, Lowpass, PLL, RPLL};
2021-02-01 01:54:09 +08:00
2021-02-19 17:44:46 +08:00
fn atan2_bench() {
2021-02-01 01:54:09 +08:00
let xi = (10 << 16) as i32;
let xf = xi as f32 / i32::MAX as f32;
let yi = (-26_328 << 16) as i32;
let yf = yi as f32 / i32::MAX as f32;
2021-02-19 17:44:46 +08:00
println!(
"atan2(yi, xi): {}",
bench_env((yi, xi), |(yi, xi)| atan2(*yi, *xi))
);
println!(
"yf.atan2(xf): {}",
bench_env((yf, xf), |(yf, xf)| yf.atan2(*xf))
);
2021-02-01 01:54:09 +08:00
}
2021-02-19 17:44:46 +08:00
fn cossin_bench() {
2021-02-01 01:54:09 +08:00
let zi = -0x7304_2531_i32;
let zf = zi as f32 / i32::MAX as f32 * PI;
2021-02-19 17:44:46 +08:00
println!("cossin(zi): {}", bench_env(zi, |zi| cossin(*zi)));
println!("zf.sin_cos(): {}", bench_env(zf, |zf| zf.sin_cos()));
2021-02-01 01:54:09 +08:00
}
2021-02-19 17:44:46 +08:00
fn rpll_bench() {
2021-02-01 01:54:09 +08:00
let mut dut = RPLL::new(8);
2021-02-19 17:44:46 +08:00
println!(
"RPLL::update(Some(t), 21, 20): {}",
bench_env(Some(0x241), |x| dut.update(*x, 21, 20))
);
println!(
"RPLL::update(Some(t), sf, sp): {}",
bench_env((Some(0x241), 21, 20), |(x, p, q)| dut.update(*x, *p, *q))
);
2021-02-01 01:54:09 +08:00
}
2021-02-19 17:44:46 +08:00
fn pll_bench() {
2021-02-01 01:54:09 +08:00
let mut dut = PLL::default();
2021-02-19 17:44:46 +08:00
println!(
"PLL::update(t, 12, 12): {}",
bench_env(0x241, |x| dut.update(*x, 12, 12))
);
println!(
"PLL::update(t, sf, sp): {}",
bench_env((0x241, 21, 20), |(x, p, q)| dut.update(*x, *p, *q))
);
2021-02-01 01:54:09 +08:00
}
2021-02-19 17:44:46 +08:00
fn iir_int_bench() {
let dut = iir_int::IIR::default();
2021-02-01 20:27:49 +08:00
let mut xy = iir_int::Vec5::default();
2021-02-19 17:44:46 +08:00
println!(
"int_iir::IIR::update(s, x): {}",
bench_env(0x2832, |x| dut.update(&mut xy, *x))
);
}
2021-02-19 17:44:46 +08:00
fn iir_bench() {
let dut = iir::IIR::default();
2021-02-01 20:27:49 +08:00
let mut xy = iir::Vec5::default();
2021-02-19 17:44:46 +08:00
println!(
"int::IIR::update(s, x): {}",
2021-04-14 22:02:54 +08:00
bench_env(0.32241, |x| dut.update(&mut xy, *x, true))
2021-02-19 17:44:46 +08:00
);
}
2021-02-27 21:54:46 +08:00
fn lowpass_bench() {
let mut dut = Lowpass::<U4>::default();
println!(
"Lowpass::<U4>::update(x, k): {}",
bench_env((0x32421, 14), |(x, k)| dut.update(*x, *k))
);
println!(
"Lowpass::<U4>::update(x, 14): {}",
bench_env(0x32421, |x| dut.update(*x, 14))
);
}
2021-02-19 17:44:46 +08:00
fn main() {
atan2_bench();
cossin_bench();
rpll_bench();
pll_bench();
iir_int_bench();
iir_bench();
2021-02-27 21:54:46 +08:00
lowpass_bench();
2021-02-19 17:44:46 +08:00
}