During application design, you need to know what to expect from the SBC in terms of computation speed to design an application that can process all coming data.
In this tutorial we present a method to measure SBC performance in different tasks and how to extrapolate it to size your application.
Measuring the code
To measure the code we use simple functions that compute the required time to send or receive a bunch of bytes. With that info we have enough to compute CPU usage and size an application.
Below we give you an example to benchmark GPS write operations. It simply sends dummy data to the GPS and measures its time. The return value has units of [bytes/second]
def benchmark_gps_write( chunk=64, N=128, baudrate=921600 ): gps = sbc.Gps( 1, baudrate ) buf = bytearray( chunk ) t0 = time.ticks_us() for i in range( N ): # send len(buf) bytes N times gps.write( buf ) t1 = time.ticks_us() dt_s = time.ticks_diff( t1, t0 )*1e-6 # Compute time size_bytes = chunk*N return size_bytes/dt_s
Results
Task | Result | Units |
---|---|---|
ubx_parser | 3.25e+04 | [B/s] |
ubx_builder | 1.09e+05 | [B/s] |
NMEA_parser | 1.47e+04 | [B/s] |
flash_write | 1.82e+04 | [B/s] |
flash_read | 4.93e+05 | [B/s] |
sd_write | 4.46e+04 | [B/s] |
sd_read | 4.26e+05 | [B/s] |
gps_write | 8.85e+04 | [B/s] |
imu_read | 4.68e+02 | [Samples/s] |
ahrs_update | 1.01e+05 | [Calls/s] |
gc_collect | 4.89e+02 | [Calls/s] |
printf | 7.67e+05 | [B/s] |
CPU usage computation
As shown in the table the SBC can send 88[KB/s] to the GPS, using the 100% of CPU. It also means that if your application sends 8.8[KB/s] to the GPS, it uses the 10% of CPU.
The same idea can be applied to any application to get an approximation of the CPU usage and size your application correctly.