Number of cycle depending on the number and type of statements

I did this little experiment to count the number of cycles per second in two different configurations:

1-The variable a is initialized at zero and incremented by one each cycle of the loop. -The value of a is written each cycle -at millis() = 1000, the incrementation ends, and the value of millis() is written to check the precision of timing.

Code:

long a = 0;
int v = 1;

void setup() {

Serial.begin(9600);

}

void loop() {

if (v == 1){
a = a + 1 ;

Serial.println(a);

if (millis() >= 1000){
Serial.println(millis());
v = 0;}

}
}

Result: 1 2 . . . 227 1000

2-Same as 1, but the value of a is written only at the end.

Code:

long a = 0;
int v = 1;

void setup() {

Serial.begin(9600);

}

void loop() {

if (v == 1){
a = a + 1 ;

if (millis() >= 1000){
Serial.println(millis());
Serial.println(a);
v = 0;}

}
}

Result:

1000 265174

-So, 227 cycles for 1, and 265174 for 2, is this correct, and can such a simple modification slow the cycling by 1000?

• Serial.print() takes a lot of time, so result is correct. – Matej Feb 7 at 16:12