Skip to content

5.3 Benchmarks and Unit Test Module

Raul Cardenas Montoya edited this page Sep 19, 2026 · 1 revision

Benchmarks and Unit Test Module

Relevant source files

The following files were used as context for generating this wiki page:

This section details the performance benchmarking architecture implemented via the Criterion harness in benches/propagate.rs, the dedicated benchmark build profile configurations in Cargo.toml, and the comprehensive unit test module located in src/tests.rs. Together, these components ensure deterministic performance regression tracking across scale boundaries and functional correctness of the routing and neuromodulation subsystems.

Sources: Cargo.toml:48-51, Cargo.toml:80-83, benches/propagate.rs:1-12, src/tests.rs:1-5


1. Criterion Benchmark Harness (benches/propagate.rs)

The benchmark suite evaluates spiking neural network propagation performance across multiple network topologies, scales, and memory management strategies benches/propagate.rs:3-7. The harness is registered as a non-native test target in Cargo.toml (harness = false) and uses the criterion crate Cargo.toml:46-50.

Parameter Matrix and Topologies

The benchmarks simulate scaled networks using deterministically generated small-world graphs via generate_small_world benches/propagate.rs:17-21. The test space explores:

  • Neuron Counts (NEURON_COUNTS): 16, 256, and 4096 neurons benches/propagate.rs:13.
  • Delay Depths: Short delays (SHORT_DELAY = 1) and long delays (LONG_DELAY = 16) benches/propagate.rs:14-15.
  • Execution Paths: Standard allocating return vs. zero-allocation caller-provided buffer reuse (propagate vs propagate_into, and propagate_graded vs propagate_graded_into) benches/propagate.rs:41-94.
graph TD
    sub53_CritMain["criterion_main!(benches)"] --> sub53_Groups["criterion_group!(benches, bench_propagate, bench_propagate_graded)"]
    sub53_Groups --> sub53_Prop["bench_propagate(c: &mut Criterion)"]
    sub53_Groups --> sub53_Grad["bench_propagate_graded(c: &mut Criterion)"]
    sub53_Prop --> sub53_MeshGen["mesh_for(n: usize, max_delay: u16)"]
    sub53_Grad --> sub53_MeshGen
    sub53_MeshGen --> sub53_SW["generate_small_world()"]
    sub53_MeshGen --> sub53_SM["SynapticMesh::new(graph)"]
    sub53_Prop --> sub53_Alloc["alloc/{label} (mesh.propagate)"]
    sub53_Prop --> sub53_Into["into/{label} (mesh.propagate_into)"]
    sub53_Grad --> sub53_GradAlloc["alloc/{label} (mesh.propagate_graded)"]
    sub53_Grad --> sub53_GradInto["into/{label} (mesh.propagate_graded_into)"]

    classDef default fill:#fff,stroke:#333,stroke-width:2px;
Loading

Figure 1: Benchmark Execution Graph from Natural Language Description to benches/propagate.rs Symbols.

Sources: Cargo.toml:46-51, benches/propagate.rs:9-97


2. Benchmark Profile and Compiler Optimization (Cargo.toml)

To ensure that micro-benchmarks reflect actual release performance while permitting profiling symbols, Cargo.toml defines a dedicated [profile.bench] section Cargo.toml:80-83.

The bench profile inherits optimizations from the release profile (opt-level = 3, lto = "thin", codegen-units = 1) but explicitly retains debug symbols (debug = true, strip = false) so external profilers (e.g., perf, flamegraph) can resolve function symbols Cargo.toml:71-83.

Sources: Cargo.toml:69-83


3. In-Crate Unit Test Suite (src/tests.rs)

The unit test module (src/tests.rs) verifies core routing logic, neuromodulatory dynamics, channel constraints, error propagation boundaries, and configuration validation rules src/tests.rs:6-221.

Key Test Categories

  • Channel Pulse Routing: Validates that pulse activation selectively targets specific channels (channel_0_pulse_activates_channel_0, channel_1_pulse_activates_channel_1) src/tests.rs:6-25 and that background noise drops below transmission thresholds (background_noise_routes_nowhere) src/tests.rs:28-32.
  • Firing Rate Bounds: Asserts that computed firing rates remain strictly bounded within 0.0..=1.0 (firing_rates_in_range) src/tests.rs:35-44.
  • Plasticity & Feedback: Verifies weight adjustments under positive and negative reinforcement (positive_feedback_increases_weight, negative_feedback_decreases_weight) src/tests.rs:47-62.
  • Neuromodulation Integration: Tests thresholding behavior, leaks, and voltage reset states in NeuromodNeuron (neuromod_neuron_fires_above_threshold, neuromod_neuron_no_fire_below_threshold) src/tests.rs:85-101.
  • Error Context Preservation: Ensures error formatting explicitly distinguishes public and internal routing methods (route_error_context_reports_public_method_name, route_modulated_error_context_reports_internal_method_name) src/tests.rs:175-205.
  • Panic Conditions: Validates defensive assertions such as panicking on zero routing timesteps (zero_routing_timesteps_panics) src/tests.rs:207-215.
graph TD
    sub53_TestMod["src/tests.rs Unit Tests"] --> sub53_CR["ChannelRouter"]
    sub53_TestMod --> sub53_NN["NeuromodNeuron"]
    sub53_TestMod --> sub53_NS["NeuromodState"]
    
    sub53_CR --> sub53_R1["channel_0_pulse_activates_channel_0"]
    sub53_CR --> sub53_R2["positive_feedback_increases_weight"]
    sub53_CR --> sub53_R3["global_gain_inhibits_firing"]
    sub53_CR --> sub53_R4["route_error_context_reports_public_method_name"]
    
    sub53_NN --> sub53_N1["neuromod_neuron_fires_above_threshold"]
    sub53_NN --> sub53_N2["neuromod_neuron_no_fire_below_threshold"]

    classDef default fill:#fff,stroke:#333,stroke-width:2px;
Loading

Figure 2: Unit Test Verification Mapping from Domain Concepts to src/tests.rs Functions.

Sources: src/tests.rs:6-215

Clone this wiki locally