相关疑难解决方法(0)

为什么memcmp比for循环检查快得多?

为什么memcmp(a, b, size)比这快得多:

for(i = 0; i < nelements; i++) {
    if a[i] != b[i] return 0;
}
return 1;
Run Code Online (Sandbox Code Playgroud)

memcmp是CPU指令还是什么?它必须非常深,因为我memcmp在循环中使用了大量的加速.

c optimization performance memcmp

28
推荐指数
1
解决办法
1万
查看次数

比较两个字符串的最佳或最快方法是什么?

我不确定下面的代码有多快.如果有人知道比这更快/更优化的代码,请告诉我.

int xstrcmp(char *s1, char *s2)
{
  while (*s1 == *s2++)
            if (*s1++ == 0)
                    return (0);
  return (*(const unsigned char *)s1 - *(const unsigned char *)(s2-1));
}
Run Code Online (Sandbox Code Playgroud)

c++ string performance

5
推荐指数
3
解决办法
1万
查看次数

标签 统计

performance ×2

c ×1

c++ ×1

memcmp ×1

optimization ×1

string ×1