ABC of Electronics cosycom.com
EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 90

Optimisation and Profiling

Measure before you tune.

Do not guess where time goes. Toggle a spare pin at the start and end of a function and measure the pulse width on an oscilloscope. That is your execution time.

Fix the biggest cost first: a better algorithm, a table instead of a calculation, or hardware like DMA. Keep the clearer code unless the speed is genuinely needed.