Timing a while loop

Hello Everyone,
I was wondering if it was possible to time (in seconds) how long a while loop runs for.

Ex. I am using linear actuator, and I have it running at full speed in a while loop until it reaches the end (then it breaks out). I was hoping I could get a value in seconds of how long that the while loop ran for (aka how long it took to extend)

Thanks!

int time=0;
while(analogRead(m1Pot) < 728){
    motor1.setSpeed(-255);
    //Want to time how long this loop runs for

}

Can try something like:

unsigned long tStart;
.
.
.
tStart = millis();
while(analogRead(m1Pot) < 728)
{
    motor1.setSpeed(-255);

}

tRunTime = ;
Serial.print( "While loop took " );
Serial.print( millis() - tStart );
Serial.println( "mS" );

That code snippet, while helpful is malformed. Plus, it’ll time more than the while loop. I would suggest not including the Serial.print which would make conclusions invalid.

tRunTime = millis() - tStart;
Serial.print( "While loop took " );
Serial.print( tRunTime );
Serial.println( "mS" );

Blackfin:
Can try something like:

unsigned long tStart;

.
.
.
tStart = millis();
while(analogRead(m1Pot) < 728)
{
    motor1.setSpeed(-255);
}

tRunTime = ;
Serial.print( "While loop took " );
Serial.print( millis() - tStart );
Serial.println( “mS” );

JimEli:
That code snippet, while helpful is malformed. Plus, it'll time more than the while loop. I would suggest not including the Serial.print which would make conclusions invalid.

tRunTime = millis() - tStart;

Serial.print( "While loop took " );
Serial.print( tRunTime );
Serial.println( "mS" );

Ironically, that's what the original intent was and then I changed my mind and went straight to printing the difference rather than using tRunTime. Mistake number 1. Mistake number 2 was not erasing the part of the original intent I typed. Thanks for the correction/clarification.

I was hoping I could get a value in seconds of how long that the while loop ran for (aka how long it took to extend)

If the time is in the order of seconds then this sounds like a job for a stopwatch rather than software.

If you are planning to use the time to carry out some action then be aware that it is likely to vary considerably depending on load and the voltage/current used.

UKHeliBob:
If the time is in the order of seconds then this sounds like a job for a stopwatch rather than software.

If you are planning to use the time to carry out some action then be aware that it is likely to vary considerably depending on load and the voltage/current used.

Im trying to do this as software because I'm trying to implement a calibration function. I have 4 actuators (and not all run at the same exact speed) and I'm trying to determine how long it takes for them to run at full speed over the 3 feet extension, so I can determine its "True Speed".

Mal-formed and flawed as my original suggestion was (see JimEli’s cleanup/corrections) I think it’s still a good bet.

If you need to be doing other things while the actuators are homing/extending consider using a state machine for each.