PWM delay problem

Hello, On the following code when I remove the "bold" code (with the calculate and the all Serial prints ) my step motor run faster. ?therwise if I run the code as it is my step motor run slower. It's like those four last lines add delay. What I can do ?

void loop() {
  sensorValue = analogRead(sensorPin);
  sensorValue = map(sensorValue,0,1023,15000,550);
  digitalWrite(13, HIGH);
  digitalWrite(13, LOW); 
[b]  float RPM = 60 /((sensorValue*1.0e-6)*400);

You are using pin toggle for the stepper motor, that will never work very well.
The calculations and Serial.print take time, but if the serial buffer is full, the Serial.print waits until the whole text is put into the buffer of the Serial library.

You can use a frequency with tone() or toneAC, or buy a chip.
Or use a dedicated library, like this one: AccelStepper: AccelStepper library for Arduino

What kind of hardware driver are you using ?

My set up is: with this driver

connecting it to an Arduino Mega

That is a simple direction and steps signal. You can make the pulses yourself for testing, after that you should use a library.

Someone asked a question about library here : and that points to the same library I mentioned before :

The documentation for that AccelStepper library is not easy, you have to initialize the library for the directions and steps signals.

This is the Playground section : There are many more libraries, but I can't find a more common one than the AccelStepper.

Is it correct if I try to solve it with timer interrupt ?

Sure, you can write your own code. But why ? Are you sure you can write code that also works when you need only one step ? The AccelStepper is already written and tested and can accelerate, that is a very nice feature :P