You are referring to different approximations. Although both compare two strings what they return (or say about the strings) is different.
===
returns only a Boolean, true or false.
strcmp
return negative (<0
) if the first string passed to the function is less than the second; positive otherwise; and zero if they are equal.
It can be said that ===
is to know if they are identical, and strcmp
is to compare strings returning 3 possibilities.
strcasecmp
is a variant of strcmp
but case-insensitive, ignoring whether it has large or small letters.
Performance:
It is only possible to compare performance differences in the case that both have in commun, that is when you want to compare if two strings are identical.
Thus, bearing in mind that strcmp
and strcasecmp
need one more check to know the result it is obvious that ===
is faster. Or are strcmp run first strcmp(strA, strB)
and then have one more equality check == 0
. However I found some numbers here which point to faster 3x performance using ===
.
Completion:
If you want to know if two strings are identical you should use ===
.
Do you know if there is any difference in performance between them?
– Rafael Withoeft
@Rafaelwithoeft added more info on the answer.
– Sergio