using micros() for execution time measurment, can it get "out of order executed"

Status
Not open for further replies.

ossi

Well-known member
using micros() for execution time measurment, can it get "out of order executed"

I am using the micros() function to measure the timing of software blocks:
Code:
start=micros()
 codeblock
stop=micros()
executionTime=stop-start
Is it possible that the compiler changes the order of execution such that the following is compiled? How is the reordering prevented?
Code:
start=micros()
stop=micros()
 codeblock
executionTime=stop-start
If I use a pin that gets toggled at start and stop the compiler sometimes does this reordering. How can I prevent the compiler from rearranging these statements?
 
@Paul: Your barrier seems to work. Thanks!
Thank you also for the Teensy boards (especially 4.0)! They have incredible power and Arduino-compatibility makes the start easy.
 
Status
Not open for further replies.
Back
Top