home *** CD-ROM | disk | FTP | other *** search
- From: cedman@lynx.ps.uci.edu (Carl Edman)
- Newsgroups: alt.sources
- Subject: Re: Fast strcmp() wanted.
- Message-ID: <CEDMAN.90Sep27075013@lynx.ps.uci.edu>
- Date: 27 Sep 90 14:50:17 GMT
- <OTTO.90Sep27145643@tukki.jyu.fi>
- Organization: non serviam
- Lines: 45
- Nntp-Posting-Host: lynx.ps.uci.edu
- In-reply-to: otto@tukki.jyu.fi's message of 27 Sep 90 12:56:43 GMT
-
- In article <OTTO.90Sep27145643@tukki.jyu.fi> otto@tukki.jyu.fi (Otto J. Makela) writes:
- 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)))
-
- If you use a good compiler (like f.e. gcc) you should get an improvement
- better than the above by simply inline-ing a self-written strcmp function.
- Another thing oyu might consider and which would be useful for some
- types of machines like f.e. 680x0 , would be to do the first few cmp-s
- as byte-cmps until you get to a longword boundary, after which you do
- longword compares. When you have got long strings which often match in
- the first part (or you often compare matching strings) then this could
- give you a really remarkable preformance improvement.
- Maybe the best way to fix your problem would be to find our if you REALLY
- need that many strcmp-s. If you f.e. do some kind of parseing and simply
- check the text against a list of keywords there are MANY better solutions,
- from sort-ing the keyword list and using a binary search, to using a
- hash-function (there are programms which can help you create them), to
- using lex.
-
-
- Theorectial Physicist,N.:A physicist whose | Send mail
- existence is postulated, to make the numbers | to
- balance but who is never actually observed | cedman@golem.ps.uci.edu
- in the laboratory. | edmanc@uciph0.ps.uci.edu
-