Skip to content
Tcl Source Code History Of Ticket 951168ffffffffffffffffffffffffffffffffff
Login

History Of Ticket 951168ffffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 951168ffffffffffffffffffffffffffffffffff

  1. Ticket change [10e35b82b6] (rid 95039) by nobody on 2004-05-10 10:38:01:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Hi, my proposal is to use the strcmp function in tclHash.c
       for comparing two strings, instead of the custom loop: 
      this should give more options to optimize the code.
      
      Giambattista Bloisi
      
      static int
      CompareStringKeys(keyPtr, hPtr)
          VOID *keyPtr;/* New key to compare. */
          Tcl_HashEntry *hPtr;/* Existing key to 
      compare. */
      {
          register CONST char *p1 = (CONST char *) keyPtr;
          register CONST char *p2 = (CONST char *) hPtr-
      >key.string;
      
      if (strcmp(p1, p2) == 0) {
      return 1;
      }
      
          return 0;
      }
      
    4. foundin initialized to: "None"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "None"
    10. title initialized to: "strcmp in CompareStringKeys"
    11. type initialized to: "RFE"
  2. Ticket change [bf08f58718] (rid 102189) by dgp on 2004-05-10 22:17:02:

    1. assignee changed to: "dkf"
    2. subsystem changed to: "10. Objects"
  3. Ticket change [012b00989f] (rid 119430) by dkf on 2004-05-10 22:30:12:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      I'm not sure how much difference that would make in
      practice.  Need to take a look at some ASM output from an
      optimising compiler :^/
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  4. Ticket change [9d83f4be3b] (rid 96318) by nobody on 2004-05-13 19:43:15:

    1. icomment:
      Logged In: NO 
      
      Hi I just wrote this little performance test. On Solaris and 
      Linux machine strcmp seems to be twice faster.
      
      #define __NO_STRING_INLINES /* get optimized assembly 
      version of strcmp with glibc */
      #include <string.h>
      #include <time.h>
      
      int test1(const char* a, const char* b)
      {
        return strcmp(a, b);
      }
      
      
      int test2(const char* p1, const char* p2)
      {
          for (;; p1++, p2++) {
              if (*p1 != *p2) {
                  break;
              }
              if (*p1 == '\0') {
                  return 1;
              }
          }
          return 0;
      
      }
      
      int main()
      {
              char a[128];
              char b[128];
              int i;
              clock_t start, end;
      
              strcpy(a, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
              strcpy(b, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab");
      
              start = clock();
              for (i=0; i< 1000000;i++)
                test1(a, b);
              end = clock();
              printf("strcmp time = %d\n", end-start);
      
              start = clock();
              for (i=0; i< 1000000;i++)
                test2(a, b);
              end = clock();
              printf("own  time = %d\n", end-start);
      
              return 0;
      }
      
      
    2. login: "nobody"
    3. mimetype: "text/plain"
    4. username: "nobody"
  5. Ticket change [3d1eb73183] (rid 121033) by dkf on 2004-05-27 17:32:58:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      I've been looking at this, and it *still* seems odd to me. 
      Which version of which compiler are you using?  With gcc
      3.2.2 on Linux, I only get optimal output if I set -O3 and
      -D__USE_STRING_INLINES.
      
      
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  6. Ticket change [259b0e4907] (rid 88198) by nobody on 2004-05-27 19:43:55:

    1. icomment:
      Logged In: NO 
      
      Well. I run the test on a dual Pentium-III (800Mhz) machine. 
      RedHat linux 7.1. glibc 2.2.5 and both 2.95.3 and 3.4.0 gcc.
      I noticed that gcc 2.95.3 produces similar results, instead 
      with 3.4.0 strcmp runs faster (probably inlines optimized 
      assembly code).
      If you want I can try to do a complete comparition on other 
      machine/compilers.
      
      Giambattista
      
      Here the results (I removed __NO_STRING_INLINES from the 
      code):
      lele@sughero[61]=> /geek-gadgets/i686-glibc22-linux/gcc-
      3.4.0/bin/gcc -O3 -march=i686 strcmpr.c        
      lele@sughero[62]=> a.out
      strcmp time = 0
      own  time = 200000
      lele@sughero[63]=> /geek-gadgets/i686-glibc22-linux/gcc-
      3.4.0/bin/gcc -O2 -march=i686 strcmpr.c 
      lele@sughero[64]=> a.out
      strcmp time = 10000
      own  time = 180000
      lele@sughero[65]=> /geek-gadgets/i686-glibc22-linux/gcc-
      3.4.0/bin/gcc -O1 -march=i686 strcmpr.c 
      lele@sughero[66]=> a.out
      strcmp time = 0
      own  time = 300000
      lele@sughero[67]=> /geek-gadgets/i686-glibc22-linux/gcc-
      3.4.0/bin/gcc -march=i686 strcmpr.c    
      lele@sughero[68]=> a.out
      strcmp time = 230000
      own  time = 470000
      
      lele@sughero[69]=> /geek-gadgets/i686-glibc22-linux/gcc-
      2.95.3/bin/gcc -march=i686 -O3 strcmpr.c   
      lele@sughero[70]=> a.out
      strcmp time = 220000
      own  time = 200000
      lele@sughero[71]=> /geek-gadgets/i686-glibc22-linux/gcc-
      2.95.3/bin/gcc -march=i686 -O2 strcmpr.c 
      lele@sughero[72]=> a.out
      strcmp time = 220000
      own  time = 210000
      lele@sughero[73]=> /geek-gadgets/i686-glibc22-linux/gcc-
      2.95.3/bin/gcc -march=i686 -O1 strcmpr.c 
      lele@sughero[74]=> a.out
      strcmp time = 230000
      own  time = 210000
      lele@sughero[75]=> /geek-gadgets/i686-glibc22-linux/gcc-
      2.95.3/bin/gcc -march=i686 strcmpr.c    
      lele@sughero[76]=> a.out
      strcmp time = 230000
      own  time = 490000
      
      
    2. login: "nobody"
    3. mimetype: "text/plain"
    4. username: "nobody"
  7. Ticket change [59e8466d82] (rid 118049) by dkf on 2004-05-27 22:11:35:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      I've updated the Tcl HEAD so that adding
      -DTCL_COMPARE_HASHES_WITH_STRCMP to your build options when
      building will make hashtables use strcmp() to compare C
      strings using code equivalent to your suggestion.  It's not
      enabled by default because I cannot duplicate your
      performance gains on my test system with a full run of Tcl;
      that machine is shared though, so I don't know if that's fair.
      
      Leaving open to remind me to revisit this at some later date.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. priority changed to: "1 Zero"
    5. resolution changed to: "Fixed"
    6. username: "dkf"
  8. Ticket change [caa4870ac1] (rid 95391) by dgp on 2007-07-03 01:21:16:

    1. icomment:
      Logged In: YES 
      user_id=80530
      Originator: NO
      
      
      Here's your reminder to revisit.
      
      I'd like to see the #ifdef and
      the custom code go away, and have
      us call strcmp() just like the OP
      here is asking.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  9. Ticket change [1b418a98ee] (rid 123115) by dkf on 2007-07-03 03:31:41:

    1. icomment:
      Logged In: YES 
      user_id=79902
      Originator: NO
      
      I still see no performance difference, even when running substantial portions of the test suite on an unloaded machine. On the other hand, I also think that cutting the clutter is a good thing... :-)
      
      Simplified in favour of strcmp() version.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  10. Ticket change [2d69c96d8e] (rid 119062) by dkf on 2007-07-03 03:31:42:

    1. closedate changed to: "2007-07-02T20:31:42"
    2. closer changed to: "dkf"
    3. status changed to: "Closed"