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

  1. From: otto@tukki.jyu.fi (Otto J. Makela)
  2. Newsgroups: alt.sources
  3. Subject: Re: Fast strcmp() wanted.
  4. Message-ID: <OTTO.90Sep27145643@tukki.jyu.fi>
  5. Date: 27 Sep 90 12:56:43 GMT
  6.  
  7. In article <1646@cherry.edc.UUCP> fraser@edc.UUCP (Fraser Orr) writes:
  8.    In article <12145@crdgw1.crd.ge.com> larocque@jupiter.crd.ge.com (David M. LaRocque) writes:
  9.    >After I profiled my C program I discovered that the function
  10.    >strcmp() takes one third of my program's CPU time.  I was hoping
  11.    >someone may have written their own version of strcmp() that
  12.    >outperforms the library's function.
  13.  
  14.    One quick dirty thing I did once was to change
  15.        if (strcmp (a,b)==0)
  16.    to
  17.        if (*a==*b && (strcmp(a.b)==0))
  18.  
  19.    I seem to remember a remarkable performance improvement, like about 5
  20.    times faster.  Probably due to the fact that the program mainly did
  21.    strcmp and the strcmp was pretty bad.
  22.  
  23. This should obviously be:
  24.     if(*a==*b && (strcmp(a,b)==0))
  25. (just in case...)
  26.  
  27. I'd believe if your compiler is really brain-damaged, this could also help
  28. a teeny weeny bit:
  29.     if(*a==*b && (!strcmp(a,b)))
  30. --
  31.    /* * * Otto J. Makela <otto@jyu.fi> * * * * * * * * * * * * * * * * * * */
  32.   /* Phone: +358 41 613 847, BBS: +358 41 211 562 (CCITT, Bell 24/12/300) */
  33.  /* Mail: Kauppakatu 1 B 18, SF-40100 Jyvaskyla, Finland, EUROPE         */
  34. /* * * Computers Rule 01001111 01001011 * * * * * * * * * * * * * * * * */
  35.