Help on speeding up datalogging into an SD card

Thanks, I'll make sure to check that out!

If I do write in the data when it is available it slows down the serial output by a lot. From what I've been reading, it seems like slowing down is expected but the values obtained from the sensors are significantly slower. Obtaining the values from the sensor slows down to a point where I can't really analyze the data because there would be so much more missing data values in between each logged one.

I wrote the code as shown below but I don't know how else to write it without significantly slowing down the serial output

if (dataFile4.open("gps.csv", O_RDWR | O_CREAT | O_AT_END))
      {
        dataFile4.print(timer);
        dataFile4.print(",");
        dataFile4.print(latitude,5);
        dataFile4.print(",");
        dataFile4.print(longitude,5);
        dataFile4.print(",");
        dataFile4.print(gps.f_altitude());
        dataFile4.print(",");
        dataFile4.print(gps.f_course());
        dataFile4.print(",");
        dataFile4.println(gps.f_speed_kmph());
      }

What would be a more efficient way to log data as it becomes available?