Arduino uno weird behavior on a simple counter program

So I just got my first Arduino Uno board and the output on the serial monitor doesn't make sense to me. For this code

int counter = 0;

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

}

void loop() {
  counter++;
  Serial.println(counter);
  delay(1);
}

I'm expecting to see an increment once every 1ms. But what I see from the console is odd


First, I'm expecting to see the timestamp like this: 27.270, 27.271, 27.272... Second, from 27.301 to 27.334, I only saw the counter increase by 7 instead of ~30.

Try a faster baud rate, like 115200. At 9600 baud it takes about four milliseconds to send each line. At that rate, it doesn't take long to fill the output buffer.

The short is that you should not rely on the timestamp that the Serial Monitor provides.

It's very well possible that Serial Monitor only polls the PC's serial buffer every 30 ms. Or that the operating system only makes the buffered data available once in a while.

If you need an accurate timestamp, add a millis() timing or a time from RTC/NTP in the message that you send to the PC.