Display execution time

Hello all!

I was wondering if in the arduino IDE there is a way to know the execution time.. for example this:

    sendNextCounter ++;
      if (sendNextCounter > 10000)
              sendNextCounter = 0;

is there a way to know how long it will take? (its just a sample to explain what I need..)

Thank you very much!

Best regards


My favourite way is to put a single instruction pin toggle either side of the code to be monitored, and using a scope or logic analyser, but be aware that this doesn’t always have zero consequences to the actual execution time.

You can also do this in software by using millis() or micros() on either side of your code.

unsigned long startTime = micros();
// code to time
unsigned long endTime = micros();
Serial.print("execution was "); Serial.print(endTime-startTime);