'Mysql PREPARE statement is taking much times at the time of record insertion

I am using PREPARE statement in store procedure but it is taking much time at the time of records insertion. Please suggest me the replacement for PREPARE statement.

SET @COUNT = 0;
SET @countQuery = CONCAT("select count(ufl.id) INTO @COUNT from user_friend_list as ufl where ufl.user_id = ",@USERREGID," AND ufl.friend_user_id = ",FID);
  PREPARE STMTC FROM @countQuery; 
 EXECUTE STMTC; 


IF @COUNT = 0 THEN
INSERT INTO user_friend_list(user_id, friend_user_id) VALUES(@USERREGID,FID),(FID,@USERREGID);
    END IF;
      DEALLOCATE PREPARE STMTC;


Solution 1:[1]

Why not just do this

IF 0 = (SELECT COUNT(*) 
          FROM user_friend_list 
         WHERE user_id = @USERREGID
           AND friend_user_id = FID) THEN
    INSERT INTO user_friend_list(user_id, friend_user_id) 
    VALUES (@USERREGID,FID), (FID,@USERREGID);
END IF; 

Here is SQLFiddle demo

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1