pub struct LatencyAnalyzer;Expand description
Stateless benchmark utility for measuring DSP processor CPU execution cost.
Implementations§
Source§impl LatencyAnalyzer
impl LatencyAnalyzer
Sourcepub fn measure_processor_execution_us<E: AudioProcessor>(
effect: &mut E,
iterations: usize,
block_size: usize,
) -> f64
pub fn measure_processor_execution_us<E: AudioProcessor>( effect: &mut E, iterations: usize, block_size: usize, ) -> f64
Measures the average wall-clock execution time of a processor in µs per sample.
Runs effect over iterations × block_size synthetic samples and returns the
mean time spent per sample. The input alternates between +0.5 and -0.5 to
exercise both halves of any branch-dependent code, and black_box prevents
dead-code elimination of the loop body.
Returns 0.0 immediately if iterations × block_size overflows or is zero.
§Arguments
effect— The processor to benchmark. Mutable because processors may carry internal filter state that updates on every sample.iterations— Number of fullblock_sizepasses to run.block_size— Samples per iteration. Larger values reduce timer-call overhead relative to actual processing; 256–2 048 is a practical range.
§Returns
Total wall-clock time divided by total samples, in microseconds per sample.
Sourcepub fn measure_effect_added_execution_us<E: AudioProcessor>(
effect: &mut E,
iterations: usize,
block_size: usize,
) -> f64
pub fn measure_effect_added_execution_us<E: AudioProcessor>( effect: &mut E, iterations: usize, block_size: usize, ) -> f64
Measures the net CPU cost added by a processor, relative to a zero-work passthrough.
Runs measure_processor_execution_us twice — once for a PassthroughProcessor
that simply returns its input unchanged, and once for effect — then subtracts the
baseline. The passthrough baseline accounts for loop overhead, Instant::now() cost,
and black_box calls, so the returned value reflects only the processor’s own work.
The result is clamped to ≥ 0.0 to avoid negative readings from measurement noise
when the processor is extremely cheap (sub-nanosecond per sample).
§Arguments
effect— The processor under test.iterations— Number of benchmark iterations (passed tomeasure_processor_execution_us).block_size— Samples per iteration.
§Returns
Net added execution cost in microseconds per sample (µs/sample), ≥ 0.