Why is strcmp so much faster than my function?
问题 I wrote a function, Str::Compare , that is basically a strcmp rewritten in another way. While comparing the two function, in a loop repeted 500'000'000 times, strcmp execute too much fast, about x750 times faster. This code was compiled in a C library with -Os parameter active: int Str::Compare(char* String_1, char* String_2) { char TempChar_1, TempChar_2; do { TempChar_1 = *String_1++; TempChar_2 = *String_2++; } while(TempChar_1 && TempChar_1 == TempChar_2); return TempChar_1 - TempChar_2;