Lag/Dropped bytes from serial input TO arduino?

I don't know enough to understand your PC program. There could be (probably will be) a problem if each call to system("echo 2 > COM4"); opens the serial port, sends the data and then closes the serial port. When the PC program opens the serial port it will cause an Uno or Mega to reset and the reset process takes time.

Your PC program should open the serial port, allow time for the reset to happen before sending the first message and then keep it open until it is completely finished with the Arduino.

If this was my project I would use a short Python program to send the data to the Arduino. This Python - Arduino demo may be of interest. But you can do the same thing using any PC programming language.

You are also using a strange baud rate. It is not listed in the table in the Atmega 328 datasheet so I have no idea how accurately the Arduino works at that rate. There is no error when using 250,000 baud or 500,000 baud.

...R