How to make Serial.print() faster?

I am working on a project trying to get the accelerometer at the sampling rate of 4K per second.
I wrote the code and I think the problem here is the Serial.print().
Since if I try to comment all those serial.print() functions. I got each loop every 260us.
Btw the core is blunt beetle and accelerometer is MPU6500. I also changed the wire band to 450000.

Here is my code. Please help! Thanks!

#include<Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
//Some of those boards have a pull-down resistor at AD0 (address = 0x68), others have a pull-up resistor (address = 0x69).
int16_t AcX,AcY,AcZ;
double ax, ay, az;

float time;

void setup() {
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0x00);     // set to zero (wakes up the MPU-6050)

  Wire.write(0x19);
  Wire.write(0x00); 
  
  Wire.write(0x1C); //accelerometer reset, band:+-2g
  Wire.write(0x00); 

  Wire.write(0x1D); //accelerometer 4K Hz sampling rate
  Wire.write(0x09);
   
  Wire.endTransmission(true);
  Serial.begin(115200);
  time = micros();
}

void loop() {
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  //Wire.endTransmission(false);//并非真的停止,还让master继续用I2
  Wire.requestFrom(MPU_addr,6,true);  // request a total of 14 registers 14个字节


  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L) 
  //ax=AcX/16383.5; 
  
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  //ay=AcY/16383.5; 
  
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  //az=AcZ/16383.5;
  
   Serial.print(AcX); //Serial.print(' ');
   Serial.print(AcY); //Serial.print(' ');
   Serial.print(AcZ); //Serial.print(' ');

   
  float temp = time - micros();
  Serial.println(temp);
  time = micros();
  
}

11520 characters per second.
You do the arithmetic.

Almost certainly you don't need to print stuff in every iteration of loop(). Maybe once per second would be sufficient.

But if you do need a fast sampling rate AND you want to see the result from each sample then I suggest you take (say) 100 samples (saved to an array) and then pause and print from the array.

I'm not sure if it will work with the Arduino Serial Monitor but you can use Serial reliably at 500,000 baud. A terminal program such as PuTTY will work at that rate.

...R

Don't unnecessarily print a float. Use the correct datatype for temp and time.

AWOL:
11520 characters per second.
You do the arithmetic.

Right. Three int16_t takes 6 bytes and one unsigned long takes 4 bytes, so technically it will be around 1K.
But if I only print the time every 1000 loop, then it will be around 1800 probably.
Is that correct?

pert:
Don't unnecessarily print a float. Use the correct datatype for temp and time.

Thx! I should use unsigned long, right?

codingpenguin:
Thx! I should use unsigned long, right?

For temperature? Do you expect the temp to be more than 65,535 degrees? Really do you expect it to be more than 255 degrees?

Temperatures can be negative.

aarg:
Temperatures can be negative.

OK, add to my list of questions, do you think you will see any negative temperatures. Once you know those things you can pick a good data type for temperature.

I don't think temp is referring to temperature here:

codingpenguin:

  float temp = time - micros();

codingpenguin:
Right. Three int16_t takes 6 bytes and one unsigned long takes 4 bytes, so technically it will be around 1K.
But if I only print the time every 1000 loop, then it will be around 1800 probably.
Is that correct?

No,it's not correct.
You're printing the values plus some spaces.

AWOL:
You're printing the values plus some spaces.

Plus some CR/LF characters generated by println().