使用strlen()与strcmp()检查空字符数组的效率对比
检查空字符数组的效率对比问题
以下是用于检查空字符数组的C++代码:
#include <iostream> #include <cstring> int main() { char c1[5]; char c2[5]; if ( strlen(c1) == 0) { std::cout<<" c1 empty"; } if (strcmp(c2, "") == 0) { std::cout<<" c2 empty"; } return 0; }
if ( strlen(c1) == 0) 对应的汇编代码如下:
lea rax, [rbp-5] movzx eax, BYTE PTR [rax] test al, al jne .L2
if (strcmp(c2, "") == 0) 对应的汇编代码如下:
movzx eax, BYTE PTR [rbp-10] movzx eax, al test eax, eax jne .L3
我无法区分这两段汇编代码,它们生成的汇编几乎一致。请问哪种检查空字符数组的方式更高效?希望能获得相关帮助或更多信息。
内容的提问来源于stack exchange,提问作者Build Succeeded
相关产品推荐
相关产品推荐

