Making program run/ react faster

I am extremely new to Arduino and have very little experience with it so halft the time i just fumbling my way through. So, my actual question is, is it possible to make this code react any faster? To be completely honest i copy and pasted this and modified to do what i need which is to set out put to low when over 1000 rpm. To give a little information im reading the flywheel magnet of a small engine and a 3144-hall effect. So, one revolution equals one signal event. hear is the code.

int ledpin = 12;
float revs;
float rpm;
volatile byte rpmcount;
long previousmicros = 0;
long interval = 1000000;
void setup() 
{
  // setup serial - diagnostics - port

  // setup pins
  pinMode(sensorPin, INPUT);
  pinMode(ledpin, OUTPUT);
  // setup interript
  attachInterrupt(0, RPM, RISING);

}
void RPM()
{
  rpmcount++;
} 
void loop() 
{
  unsigned long currentmicros = micros();
  int sensorValue = digitalRead(sensorPin);
  if (currentmicros - previousmicros > interval)  {
    previousmicros = currentmicros;

    detachInterrupt(0);
    revs=2000000.0/rpmcount;
    rpm = 60000000.0/revs;

    rpmcount=0;
    attachInterrupt(0, RPM, RISING);

  }
  if (rpm >= 1200) {
    digitalWrite (ledpin, LOW);
  }
  else {
    digitalWrite(ledpin, HIGH);  
  }
}```

attachInterrupt should be placed in setup. Drop detach.
Use disable and enable interrupt in loop.
Check Arduino/reference for interrupt handling.

Your program fails to compile here

Also, floating point divisions are much slower than integer divisions. You can change them to a single integer operation and make your loop way faster.

And, move the LED status change instructions next to the rpm calculation. The LED state does not change if the rpm stays the same (rpm is an invariant outside the interval check).

Hall effect output is NPN open collector, your setup() should be:

  // setup pins
  pinMode(sensorPin, INPUT_PULLUP);
  pinMode(ledpin, OUTPUT);
  // setup interript
  attachInterrupt(0, RPM, FALLING);

See datasheet page 4:

https://www.mpja.com/download/a3144eul.pdf

The above can be simplified as

rpm = 30 * rpmcount;

If your counting interval is one second, why did you multiply to 30 for rpm ?

because I'm using someone else code. this is honestly way over my head i simplfied as you stated but it did not change the speed of the operation.

so? what would the single integer look like? I did move the led instruction but dident seam to have much effect

``int sensorPin = 2; //hall effect
int ledpin = 12;
float revs;
float rpm;
volatile byte rpmcount;
long previousmicros = 0;
long interval = 1000000;
int sensorValue = digitalRead(sensorPin);
void setup()
{
// setup serial - diagnostics - port

// setup pins
pinMode(sensorPin, INPUT);
pinMode(ledpin, OUTPUT);
// setup interript

}
void RPM()
{
rpmcount++;
}
void loop()
{
unsigned long currentmicros = micros();

if (currentmicros - previousmicros > interval) {
previousmicros = currentmicros;

detachInterrupt(0);
//revs=2000000.0/rpmcount;
//rpm = 60000000.0/revs;
rpm = 30 * rpmcount;

if (rpm >= 1200) {
digitalWrite (ledpin, LOW);
}
else {
digitalWrite(ledpin, HIGH);
}
rpmcount=0;
attachInterrupt(0, RPM, RISING);

}

}``

What exactly do you mean by this? How do you measure the speed and then decide if the executions time improved?

Then you decided to copy the wrong program if you want really fast reaction! Your code is counting revolutions and making a calculation.
If fast response is required, measure the time between two pulses and when the time is equal to greater than 1,000 rpm, make your move! Any single motor revolution will be able to trigger your test.

As @Paul_KD7HB says you are counting revolutions in 1 sec and then you turn on/off the led.
This is not very 'responsive' as it will take 'around 1 sec' to visualize the speed variations.
The proposed solution ( counting the period between two pulses ) is the 'fastest', but consider that around the trigger frequency the led will flicker a little, which is good, for a led, but not if you intend to use this output to drive a relay, a load ( in this case the flickering is not good at all ).

P.S. also consider that having only one pulse x revolution you vill have only 20 count each second at 1200rpm, and every count is +/-60rpm ( you considered 30 in your code ), if you need more resolution use more pulses x revolution.

As other mentioned above, the reaction speed of your program exactly coded in this line:

The code outputs the result every 1second and this time depends only on the value of interval parameter and not on the code.