Serial.print high latency?

I have a connector with 84 pins, where I have to measure the resistance between every pin for testing.
The measurement procedure is as follows:

  • set the multiplexer
  • read the ADC
  • send the measured value to the UART

I use the Arduino Nano Every with the ATmega4809. The SPI runs at 8MHz and the UART at 1MHz, which works without a problem. But I noticed a relatively large delay between the ADC measurement and the beginning of the UART transfer of about 150us.
You can see this delay in the attachment "Serial_print.png"

This is the used code:

for(int i = 1; i <= 84; i++){
    MUX_setHigh(i);
    for (int j = 1; j <= 84; j++){
        MUX_setLow(j);
        adcval = ADC_readRAW();
        Serial.print(adcval);
    }
}

But if I use "Serial.write" instead of "Serial.print", this delay is almost gone. You can see this in the attachment "Serial_write.png".
This is the code:

for(int i = 1; i <= 84; i++){
    MUX_setHigh(i);
    for (int j = 1; j <= 84; j++){
        MUX_setLow(j);
        adcval = ADC_readRAW();
        Serial.write((adcval >> 8) & 0xFF);
        Serial.write(adcval & 0xFF);
    }
}

If possible I would rather use Serial.print, because the values are directly readable in the serial monitor.

Does anyone know why Serial.print has a higher delay than Serial.write?

Serial_print.png

Serial_write.png

Does anyone know why Serial.print has a higher delay than Serial.write?

Because it does a lot more. Serial.write() just writes out a byte to the serial buffer which is clear as fast a possible afterwards. If you use the print() method in most situations a conversion is done to actually write a decimal representation of the value in ASCII characters to the serial interface. This conversion needs some of course.