Skip to content

Commit

Permalink
try iai-callgrind
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Jan 12, 2024
1 parent 50576e3 commit 653f179
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 95 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ easybench = "1.0"
rand = "0.8"
ndarray = "0.15"
rustfft = "6.1.0"
iai-callgrind = "0.10.0"
# futuredsp = "0.0.6"
# sdr = "0.7.0"

Expand Down
106 changes: 11 additions & 95 deletions benches/micro.rs
Original file line number Diff line number Diff line change
@@ -1,103 +1,19 @@
use core::f32::consts::PI;
use core::hint::black_box;

use easybench::bench_env;
use iai_callgrind::{library_benchmark, library_benchmark_group, main};

use idsp::{atan2, cossin, iir, Filter, Lowpass, PLL, RPLL};

fn atan2_bench() {
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;

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))
);
}

fn cossin_bench() {
let zi = -0x7304_2531_i32;
let zf = zi as f32 / i32::MAX as f32 * PI;
println!("cossin(zi): {}", bench_env(zi, |zi| cossin(*zi)));
println!("zf.sin_cos(): {}", bench_env(zf, |zf| zf.sin_cos()));
}

fn rpll_bench() {
let mut dut = RPLL::new(8);
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))
);
}

fn pll_bench() {
let mut dut = PLL::default();
println!(
"PLL::update(Some(t), 12, 12): {}",
bench_env(Some(0x241), |x| dut.update(*x, 12))
);
println!(
"PLL::update(Some(t), sf, sp): {}",
bench_env((Some(0x241), 21), |(x, p)| dut.update(*x, *p))
);
#[library_benchmark]
#[bench::some(-0x7304_2531_i32)]
fn bench_cossin(zi: i32) {
black_box(cossin(zi));
}

fn iir_int_bench() {
let dut = iir::Biquad::default();
let mut xy = [0; 4];
println!(
"int_iir::IIR::update(s, x): {}",
bench_env(0x2832, |x| dut.update(&mut xy, *x))
);
}

fn iir_f32_bench() {
let dut = iir::Biquad::<f32>::default();
let mut xy = [0.0; 4];
println!(
"int::IIR::<f32>::update(s, x): {}",
bench_env(0.32241, |x| dut.update(&mut xy, *x))
);
}

fn iir_f64_bench() {
let dut = iir::Biquad::<f64>::default();
let mut xy = [0.0; 4];
println!(
"int::IIR::<f64>::update(s, x): {}",
bench_env(0.32241, |x| dut.update(&mut xy, *x))
);
}

fn lowpass_bench() {
let mut dut = Lowpass::<1>::default();
println!(
"Lowpass::<1>::update(x, k): {}",
bench_env((0x32421, 14), |(x, k)| dut.update(*x, &[*k]))
);
println!(
"Lowpass::<1>::update(x, 14): {}",
bench_env(0x32421, |x| dut.update(*x, &[14]))
);
}
library_benchmark_group!(
name = bench_cossin_group;
benchmarks = bench_cossin
);

fn main() {
atan2_bench();
cossin_bench();
rpll_bench();
pll_bench();
iir_int_bench();
iir_f32_bench();
iir_f64_bench();
lowpass_bench();
}
main!(library_benchmark_groups = bench_cossin_group);

0 comments on commit 653f179

Please sign in to comment.