Speeding up sample rate - Data logger

Hi,
I’ve made myself a data logger. It records barometric pressure, and converts to altitude, applies a filter to get rid of the noise and writes it to an SD card. It will hopefully go into a model rocket to be able to plot altitude-time data.
However-I can only get it to sample at 10Hz currently, which seems a bit slow to me? I’m a bit of a noob so there may be many ways to make the code more efficient, but I don’t really know how.
I tried to comment out all the ‘Serial.print’ lines at the bottom, and it had no effect on speed.

Any ideas or info would be greatly appreciated thanks.

void loop()
{
  int buttonstate = digitalRead(buttonpin);
  
  if (buttonstate == 1)
  {
    active = 1;
    delay(1000);
  }
  
  if (id==1 && active==1)
  {
    starttime = millis();
  }
  
  if(id<20 && active==1)
  {
  File logFile = SD.open("TEST7.csv", FILE_WRITE);
 if(logFile)
{
  float clock = millis() - starttime;
  float time = clock/1000;
  
  String dataString = String(id) + ", ";
  a = bmp.readAltitude(bmp.readPressure());
  
  p=p+q;
  k=p/(p+r);
  x=x+k*(a-x);
  p=(1-k)*p;
  
  logFile.print(dataString);
  logFile.print(time);
  logFile.print(", ");
  logFile.print(a);
  logFile.print(", ");
  logFile.println(x);
  logFile.close();
 Serial.print(dataString);
 Serial.print(time);
 Serial.print(", ");
 Serial.print(a);
 Serial.print(", ");
 Serial.println(x);
 
 buttonstate = digitalRead(buttonpin);
  if (buttonstate == 1)
  {
    active = 0;
    delay(1000);
  }
 
}
else
{
  Serial.println("Couldn't access SD Card file");
}
id++;
  }
}

Open the file in setup() instead of every time through loop().

If the SD card isn't fast enough, try an external FRAM chip.

By closing the file after every sample you're forcing the SD to commit each sample one at a time. That is very inefficient since the SD will be allocating and storing the data in blocks. It will go much faster if you leave the file open since the SD library can then buffer the updates and write them in blocks. I suggest you look at the Ardulog code to see how to write to SD storage efficiently.