Puzzled about fast timer

I copied some code for a simple countdown timer which works perfectly in the example.

When I run it there is about a 12 second delay before the countdown actually starts ( in my code) and the loop runs through at a very fast pace until it has caught up to the 12 seconds, and then slows to 1 second countdown.

I don't understand why it would do that? Can anyone advise?

int min = 60;
int sec = 00;
unsigned long oneSecond = 1000UL;
unsigned long startTime;

void setup(){
Serial.begin(9600);
sec = sec + 60 * min;
// if you add a delay of 10 seconds here, you will see how it "catches up" before executing the code correctly.
}
//----------------------------------------------------
void loop()
{
if (millis() - startTime >= oneSecond)
{
sec--;
startTime += oneSecond;
if (sec <= 0) KaBoom();
int displayMin = sec/60;
if (displayMin < 10) Serial.print("0");
Serial.print(displayMin);
Serial.print(":");
int displaySec = sec % 60;
if (displaySec < 10) Serial.print("0");
Serial.println(sec % 60);
}
}
void KaBoom()
{
Serial.println("The world has ended");
while(1)
{

}
}

Add...

startTime = millis();

...at the end of setup()

When the Arduino boots, whatever code is running in setup takes 12 seconds to execute.
millis() is therefore returning 12000 the first time through loop() with startTime is zero.
The if condition “millis() - 0 >= 1000“ is therefore true, and the code adds 1000 to startTime.
This process repeats rapidly each time through loop() until the condition “millis() - startTime >= oneSecond” is false, i.e. startTime has had 1000 added to it enough times to exceed the current value returned by millis(). Execution of the if statement then returns to 1 second intervals.

Works fine on my Arduino UNO. No significant delay starting the countdown and it counts down at one-second intervals, as near as I can tell. Did you add a delay in the place that says:

  // if you add a delay of 10 seconds here, you will see how it "catches up" before executing the code correctly.

johnwasser:
Works fine on my Arduino UNO. No significant delay starting the countdown and it counts down at one-second intervals, as near as I can tell. Did you add a delay in the place that says:

  // if you add a delay of 10 seconds here, you will see how it "catches up" before executing the code correctly.

If you read between the lines of the OPs post you will see this is not their actual code, but a minimal recreate.
Yes, I assume they have to put the artificial delay in to recreate the problem exhibited by their code (because, being more complex, it is presumably doing more stuff in setup()).

Thanks pcbbc.

That was exactly it. Sorry if I didn't make it more clear in the OP. Appreciate all the input.