Class anira::benchmark::ProcessBlockFixture¶
-
class ProcessBlockFixture : public benchmark::Fixture¶
Inheritance diagram for anira::benchmark::ProcessBlockFixture:
Collaboration diagram for anira::benchmark::ProcessBlockFixture:
Benchmark fixture class for testing neural network inference performance in audio processing contexts.
The ProcessBlockFixture provides a specialized Google Benchmark fixture for measuring the performance of neural network inference operations in real-time audio processing scenarios. It manages test setup, data preparation, timing measurements, and cleanup for benchmarking different inference backends, model configurations, and buffer sizes.
This fixture supports:
Performance testing across different inference backends (ONNX, LibTorch, TensorFlow Lite, Custom)
Benchmarking with various audio buffer sizes and sample rates
Detailed timing measurements and reporting for each iteration and repetition
Automated test data generation and buffer management
Cross-platform timing precision handling
Note
This class inherits from Google Benchmark’s Fixture class and should be used with the BENCHMARK_F macro for defining benchmark tests.
Public Functions
-
ProcessBlockFixture()¶
Default constructor that initializes the benchmark fixture.
Sets up initial state for benchmarking, including buffer size and repetition counters. A new instance is created for each benchmark that has been defined and registered.
-
~ProcessBlockFixture()¶
Destructor that cleans up benchmark resources.
-
void initialize_iteration()¶
Initializes the current benchmark iteration.
Prepares the benchmark for a new iteration by capturing the current state of processed samples. This method should be called at the beginning of each benchmark iteration to establish a baseline for measuring progress.
-
void initialize_repetition(const InferenceConfig &inference_config, const HostConfig &host_config, const InferenceBackend &inference_backend, bool sleep_after_repetition = true)¶
Initializes a new benchmark repetition with specified configurations.
Sets up the benchmark environment for a new repetition, including inference configuration, audio settings, and backend selection. Handles switching between different configurations and provides detailed logging of the test setup.
- Parameters:
inference_config – Reference to the inference configuration containing model settings
host_config – Audio host configuration with sample rate and buffer size settings
inference_backend – The backend type to use for inference (ONNX, LibTorch, etc.)
sleep_after_repetition – Whether to sleep after each repetition to allow system cooldown (default: true)
-
bool buffer_processed()¶
Checks if the current audio buffer has been fully processed.
Determines whether the inference handler has processed all samples that were pushed since the last iteration initialization.
- Returns:
True if the buffer has been processed, false otherwise
-
void push_random_samples_in_buffer(anira::HostConfig host_config)¶
Fills the audio buffer with random sample data.
Generates random audio samples and populates the internal buffer according to the specified host configuration. Used to create test data for benchmarking.
- Parameters:
host_config – Audio host configuration specifying buffer size and channel count
-
int get_buffer_size()¶
Gets the current buffer size being used for benchmarking.
- Returns:
The buffer size in samples
-
int get_repetition()¶
Gets the current repetition number.
- Returns:
The number of the current benchmark repetition
-
void interation_step(const std::chrono::system_clock::time_point &start, const std::chrono::system_clock::time_point &end, ::benchmark::State &state)¶
Records timing information for a single benchmark iteration (Windows/macOS)
Measures and records the elapsed time for a single benchmark iteration using steady_clock for high precision timing on Windows and macOS platforms. Updates benchmark state and provides detailed logging of iteration results.
Records timing information for a single benchmark iteration (Linux/Unix)
Measures and records the elapsed time for a single benchmark iteration using system_clock for timing on Linux and Unix platforms. Updates benchmark state and provides detailed logging of iteration results.
- Parameters:
start – The start time point of the iteration
end – The end time point of the iteration
state – Reference to the benchmark state for recording results
start – The start time point of the iteration
end – The end time point of the iteration
state – Reference to the benchmark state for recording results
-
void repetition_step()¶
Finalizes the current benchmark repetition.
Performs cleanup and logging tasks at the end of a benchmark repetition. Increments the repetition counter and provides visual separation in the output.
Public Static Attributes
-
static std::unique_ptr<anira::InferenceHandler> m_inference_handler = nullptr¶
Static shared pointer to the inference handler used across benchmark instances.
This shared inference handler is used by all benchmark instances to perform neural network inference operations. It’s managed as a static member to avoid repeated initialization costs during benchmarking.