home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
1
/
1882
< prev
next >
Wrap
Internet Message Format
|
1990-12-28
|
1KB
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
In article <CEDMAN.90Sep27075013@lynx.ps.uci.edu>
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.