Is this a correct code to count the loop speed?

Hi guys!!! is this a correct code to count the loop speed?

unsigned long previousCurrentTime;

void setup() {
  Serial.begin(9600);
}

void loop() {
  unsigned long currentTime = micros();






  //delay (19);

  

  unsigned long loopSpeed = currentTime - previousCurrentTime;
  Serial.println (loopSpeed);


  




  previousCurrentTime = currentTime;
}

No.

previousCurrentTime

Lol at the name there. Bit if an oxymoron no?

As written it just gets the time between those two statements, not the whole loop.

It would be much better to measure the time for 1000 or 10,000 iterations of loop().

And make sure all the print statements are outside the timed interval.

...R

Whatever method you use it is only going to provide the speed for the loop() function containing those instructions. Change the instructions and the speed will change.

so i understand that it is correct by approach if you want to know how fast your code execute.

unsigned long previousCurrentTime;

void setup() {
  Serial.begin(9600);
}

void loop() {
  unsigned long currentTime = micros();

//----------------------------------------------




// put your main code here, to run repeatedly:




  
//---------------------------------------------------

//loop speed counter
  unsigned long loopSpeed = currentTime - previousCurrentTime;
  Serial.println (loopSpeed);
  previousCurrentTime = currentTime;
}

Robin2:
It would be much better to measure the time for 1000 or 10,000 iterations of loop().

this sounds good idea.