Path: utzoo!utgpu!cs.utexas.edu!usc!ucsd!ucbvax!bloom-beacon!eru!hagbard!sunic!news.funet.fi!tukki.jyu.fi!jyu.fi!otto From: otto@tukki.jyu.fi (Otto J. Makela) Newsgroups: alt.sources Subject: Re: Fast strcmp() wanted. Message-ID: Date: 27 Sep 90 12:56:43 GMT References: <12145@crdgw1.crd.ge.com> <1646@cherry.edc.UUCP> Sender: news@tukki.jyu.fi (News articles) Organization: Turing Police, Criminal AI section Lines: 28 In-Reply-To: fraser@edc.UUCP's message of 26 Sep 90 16:26:26 GMT In article <1646@cherry.edc.UUCP> fraser@edc.UUCP (Fraser Orr) writes: In article <12145@crdgw1.crd.ge.com> larocque@jupiter.crd.ge.com (David M. LaRocque) writes: >After I profiled my C program I discovered that the function >strcmp() takes one third of my program's CPU time. I was hoping >someone may have written their own version of strcmp() that >outperforms the library's function. 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. This should obviously be: if(*a==*b && (strcmp(a,b)==0)) (just in case...) I'd believe if your compiler is really brain-damaged, this could also help a teeny weeny bit: if(*a==*b && (!strcmp(a,b))) -- /* * * Otto J. Makela * * * * * * * * * * * * * * * * * * */ /* Phone: +358 41 613 847, BBS: +358 41 211 562 (CCITT, Bell 24/12/300) */ /* Mail: Kauppakatu 1 B 18, SF-40100 Jyvaskyla, Finland, EUROPE */ /* * * Computers Rule 01001111 01001011 * * * * * * * * * * * * * * * * */