What is the best or fastest way to compare two strings?

I'm not sure how fast the code is below. If anyone knows a faster / optimized code than this, please let me know.

int xstrcmp(char *s1, char *s2)
{
  while (*s1 == *s2++)
            if (*s1++ == 0)
                    return (0);
  return (*(const unsigned char *)s1 - *(const unsigned char *)(s2-1));
}
+3
source share
3 answers

::strcmp . , , , , (, SSE4.2 ). MSVC , , ( ), VS2010, VC/crt/src/intel/strcmp.asm.)

+13

, , strcmp? C strcmp .

, :

  • memcmp, .
  • 4 8 , int32 int64 .
    • , 4- 8- , , .
+4

, :

if (a[0]==b[0] && strcmp(a, b)==0){.....

strcmp, , .

+4

Source: https://habr.com/ru/post/1674399/


All Articles