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 >
Internet Message Format  |  1990-12-28  |  1KB

  1. From: dfs@doe.carleton.ca (David F. Skoll)
  2. Newsgroups: alt.sources
  3. Subject: Re: Fast strcmp() wanted.
  4. Message-ID: <1990Sep27.151543.8025@ccs.carleton.ca>
  5. Date: 27 Sep 90 15:15:43 GMT
  6.  
  7. In article <CEDMAN.90Sep27075013@lynx.ps.uci.edu>
  8. cedman@lynx.ps.uci.edu (Carl Edman) writes:
  9.  
  10. >      One quick dirty thing I did once was to change
  11. >          if (strcmp (a,b)==0)
  12. >      to
  13. >          if (*a==*b && (strcmp(a,b)==0))
  14. >
  15. >      I seem to remember a remarkable performance improvement, like about 5
  16. >      times faster.  Probably due to the fact that the program mainly did
  17. >      strcmp and the strcmp was pretty bad.
  18.  
  19. Hmm... that seems strange.  If the first characters of the strings differ,
  20. most strcmps will not bother to test the rest.  All that the above code
  21. possibly saves you is a function call/return.  If this makes such a huge
  22. difference, then the compiler or your machine's architecture must be pretty
  23. bad.
  24. --
  25. David F. Skoll        | Department of Electronics | Opinions expressed here are
  26. dfs@doe.carleton.ca   | Carleton University       | my own and not necessarily
  27. (613) 788-5771 | 5772 | Ottawa, Ontario, Canada   | those of my employer.
  28.