Path: utzoo!dciem!nrcaer!cunews!dfs From: dfs@doe.carleton.ca (David F. Skoll) Newsgroups: alt.sources Subject: Re: Fast strcmp() wanted. Message-ID: <1990Sep27.151543.8025@ccs.carleton.ca> Date: 27 Sep 90 15:15:43 GMT References: <1646@cherry.edc.UUCP> Sender: news@ccs.carleton.ca (news) Organization: Department of Electronics, Carleton University, Ottawa, Canada Lines: 21 In article cedman@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@doe.carleton.ca | Carleton University | my own and not necessarily (613) 788-5771 | 5772 | Ottawa, Ontario, Canada | those of my employer.