HAL_Delay() affecting function execution times
Hi,
I'm trying to measure the execution time of an algorithm using the Cortex-M7 on a Nucleo-H745ZI-Q. I'm measuring the execution time using a GPIO pin and the DWT cycle counter register. Here's the form this profiling takes in my while (1) loop.

I'm seeing some unexpected behavior when running experiments with different optimization flags:
- When I compile with the -O3 flag, I'm seeing the execution time of the algorithm roughly half when I remove the call to HAL_Delay() (observed on the scope, and number of cycles).
- When I compile with the -Ofast flag, I'm seeing the execution time of the algorithm roughly double when I remove the call to HAL_Delay() (observed on both scope, and number of cycles).
I'm changing the optimization flags through the project properties -> C/C++ build -> Settings menu in the STM32CubeIDE. The algorithm is utilizing CMSIS DSP instructions. I'm not seeing this behavior when doing the same thing on a NUCLEO-G491RE. What steps should I be taking to figure out what's causing this weirdness?
TIA,
stn
