vito576 wrote: ↑Mon Mar 04, 2024 4:27 pm
As stated in my first post I'm using ESPRESSIF example on evaluating performance, the code I'm using is there...
The performance measurement code is there. Not the code of your important_functions. It could be that the compiler messes with the resulting machine code of that (inlining functions etc) depending on how you invoke them.
your performance evaluation code adds time, or the compiler can optimize by combining something in the calls to both functions so the total takes less.
So, I guess is the latter case since I'm using ESPRESSIF example?
Yes.
I'm still confused with the behavior on evaluating performance of vTaskDelay with custom functions. Specifically with the actual output I provided where I expected at least the performance to vary a little where I excluded my custom function:
(I test this with different functions that individually takes less than 766 microseconds and more, and got the same results)
That doesn't happen because what I explained earlier. To clarify:
- A 'tick' is an unit of 1ms in your case.
- A 'tick boundary' is when FreeRTOS decides a tick ends and starts a new tick.
- Your important_function starts on a tick boundary; the CPU still has 1 ms left before a new tick.
- Your important_function ends 766 ms later; the CPU still has 0.244uS left before a new tick. Total time taken = 766 uS.
- You call vTaskDelay(2). This waits two tick
boundaries.
- The first tick boundary arrives 0.244uS later. Total time taken = 1mS.
- The second tick boundary arrives 1mS later. Total time taken = 2mS.
- Your program continues another loop. This loop took exactly 2mS. Note that this is independent of how long the important_function takes exactly; because vTaskDelay 'fills out' the first tick, this will always be 2mS precise.
Well, at the end the conclusion(?) seems to be that the performance of individual functions cannot be measure with accuracy (have poor repeatibility is likely a better term) so is wrong to expect the time of execution of different functions to add up. This is not a problem for me right now, but this leads me to the following question for any future use of my esp32:
I don't think you can conclude that at all. As I said before, the example with vTaskDelay works exactly as you'd imagine it would if you take the quirks of vTaskDelay into account. I think your second example also works fine; if you give the code of the two functions you're trying to measure I can look a bit deeper.