Fast strcmp() wanted.

David F. Skoll dfs at doe.carleton.ca
Fri Sep 28 01:15:43 AEST 1990


In article <CEDMAN.90Sep27075013 at lynx.ps.uci.edu>
cedman at lynx.ps.uci.edu (Carl Edman) writes:

>      One quick dirty thing I did once was to change
>	      if (strcmp (a,b)==0)
>      to
>	      if (*a==*b && (strcmp(a,b)==0))
>
>      I seem to remember a remarkable performance improvement, like about 5
>      times faster.  Probably due to the fact that the program mainly did
>      strcmp and the strcmp was pretty bad.

Hmm... that seems strange.  If the first characters of the strings differ,
most strcmps will not bother to test the rest.  All that the above code
possibly saves you is a function call/return.  If this makes such a huge
difference, then the compiler or your machine's architecture must be pretty
bad.
--
David F. Skoll        | Department of Electronics | Opinions expressed here are
dfs at doe.carleton.ca   | Carleton University       | my own and not necessarily
(613) 788-5771 | 5772 | Ottawa, Ontario, Canada   | those of my employer.



More information about the Alt.sources mailing list