Files
chanora/crates/chanora_audio/benches/resampler.rs
T

54 lines
2.2 KiB
Rust

// SDD-120 §3 item 5 — resampler throughput bench.
//
// The chanora_audio engine uses a hand-rolled linear resampler
// inside CaptureState (see engine.rs `resample_into_accum`); there
// is no rubato dependency. The bench drives the same code path
// via the §3 bench seam by instantiating CaptureBenchHandle at
// different `in_sample_rate` values (44_100, 16_000, 48_000) and
// feeding a 1-second buffer per iteration. Throughput is reported
// as samples/sec via criterion's `Throughput::Elements`.
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "android"))]
fn main() {}
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "android")))]
use chanora_audio::bench_seam::CaptureBenchHandle;
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "android")))]
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "android")))]
mod common;
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "android")))]
use common::synthetic_capture_buffer;
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "android")))]
fn bench_resampler_throughput(c: &mut Criterion) {
let mut group = c.benchmark_group("resampler_throughput");
for (label, in_rate, frames) in [
("44100_to_48000", 44_100u32, 44_100usize),
("16000_to_48000", 16_000u32, 16_000usize),
("48000_passthrough", 48_000u32, 48_000usize),
] {
let buf = synthetic_capture_buffer(frames, 1);
let mut handle = CaptureBenchHandle::new(in_rate, 1);
// Pre-warm so the first allocation does not dominate.
for _ in 0..4 {
handle.ingest_f32(&buf);
}
group.throughput(Throughput::Elements(frames as u64));
group.bench_function(label, |b| {
b.iter(|| {
handle.ingest_f32(black_box(&buf));
});
});
}
group.finish();
}
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "android")))]
criterion_group!(resampler, bench_resampler_throughput);
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "android")))]
criterion_main!(resampler);