httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Douglass <miked...@texas.net>
Subject Closing strcasestr discussion...
Date Fri, 12 Jul 1996 00:42:21 GMT
On Thu, 11 Jul 1996, Michael Douglass wrote:

Ok, I accept defeat!  :)  Hate it when I have to be the one to try and
benchmark something and find that what I thought would be faster is
actually 3 times slower (roughly)...  This was not an exact bench mark
as I ran the preliminaries and saw the difference myself.  Running
50000 lines through the two routines discussed, the one stepping through
s1 one character at a time calling strncasecmp is actually faster on
my linux box.  Geee.. i just did it on my SunOS 4.1.4 machine and here
are the results from time:

my method:
        6.1 real         5.7 user         0.2 sys  
other method:
        1.4 real         1.3 user         0.1 sys  

The part that actually makes mine slower is where I am converting the
string to lower case.  Hrm... overhead from the repeated function call
tolower() maybe?  I'll have to look at the GNU implementation of 
strncasecmp() and see how they are doing it... For curiosity's sake...

And just to make sure you understand me fully... THE SLOW PART WAS THE
CONVERSION... mallocing the ram and freeing it had *NO* affect on the
time table.  I ran two versions of my strcasestr; one with the
malloc()s and free()s, and one that simply used the strings themselves
(hey, this is a benchmark so that's legal since it shows very little
difference in time for malloc/free--and that seems to be a common
misconception).

my method w/o malloc/free calls:
        5.5 real         4.6 user         0.3 sys

Sure it showed about a .6 real, and .9 user and .1 sys difference in time;
but that is for handling 50000 records...  Too small to be noticed or 
worried about.

So, if I had to vote it would be +1 for this routine:

char *strcasestr( char *s1, char *s2 )
{
    int len = strlen(s2);
    while (*s1) {
        if (!strncasecmp(s1, s2, len))
            return s1;
        s1++;
    }
    return NULL;
}

CASE CLOSED... :)  (finally!)

Michael Douglass
Texas Networking, Inc.

  "To be a saint is to be an exception; to be a true man is the rule.
   Err, fail, sin if you must, but be upright.  To sin as little as
   possible is the law for men; to sin not at all is a dream for angels."

              - Victor Hugo, "Les Miserables"


Mime
View raw message