sms based door lock

sms.IsSMSPresent() is a function outside your code, in a library. I don't know what it does and if you want you can attach this library. I guess however that the function sends a command to the phone, something like AT+CGML="REC UNREAD", which lists the unread messages in the phone's memory. The problem is that it is blocking, it must wait for the modem response, and takes time even if there are no messages. You can measure the time it takes using millis(), this way:

millis spent in sms.IsSMSPresent: 91
millis spent in sms.IsSMSPresent: 91
millis spent in sms.IsSMSPresent: 91
millis spent in sms.IsSMSPresent: 91
millis spent in sms.IsSMSPresent: 91
millis spent in sms.IsSMSPresent: 90

This is what it show when I test the time millis between

this code

 unsigned long elapsed_millis;
  unsigned long start_millis = millis();
 char pos =  sms.IsSMSPresent(SMS_UNREAD);
 if (pos) {
  sms_detected();
 }
 
  elapsed_millis = millis() - start_millis;
  Serial.print("millis spent in sms.IsSMSPresent: ");
  Serial.println(elapsed_millis);