home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
1
/
1872
< prev
next >
Wrap
Internet Message Format
|
1990-12-28
|
1KB
From: otto@tukki.jyu.fi (Otto J. Makela)
Newsgroups: alt.sources
Subject: Re: Fast strcmp() wanted.
Message-ID: <OTTO.90Sep27145643@tukki.jyu.fi>
Date: 27 Sep 90 12:56:43 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 <otto@jyu.fi> * * * * * * * * * * * * * * * * * * */
/* 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 * * * * * * * * * * * * * * * * */