benchmark
index
/home/runner/work/jsa/jsa/tests/benchmark.py

Sampling-rate benchmark for the JSignalAnalysis ATmega328P firmware.
 
Measures the actual sample throughput at each supported rate (1/10/20 kHz)
over a configurable duration and reports the deviation from the target.
 
Usage::
 
    python benchmark.py                   # auto-detect Arduino port
    python benchmark.py --port=/dev/ttyACM0

 
Modules
       
serial
sys
time

 
Functions
       
find_arduino_port()
Auto-detects the serial port of the Arduino.
Returns the port name (e.g., '/dev/ttyACM0' or 'COM3').
Raises Exception if not found.
run_benchmark()
Execute the sampling-rate benchmark across all configured test cases.
 
Steps:
    1. Detect (or accept) a serial port.
    2. For each rate in ``TEST_CASES``: set the rate, start acquisition,
       count received bytes over ``MEASURE_DURATION`` seconds, stop, and
       compute the actual Hz and error percentage.
    3. Print a summary table to stdout.

 
Data
        BAUD_RATE = 2000000
MEASURE_DURATION = 10.0
TEST_CASES = [{'cmd': b'\x10', 'name': '1 kHz', 'target': 1000}, {'cmd': b'\x11', 'name': '10 kHz', 'target': 10000}, {'cmd': b'\x12', 'name': '20 kHz', 'target': 20000}]