Re: strncasecmp

2016-06-08 Thread William A Rowe Jr
So, finally looping back to the httpd vs. apr implementations of these functions... apr was testing null against equality and both *str1 null and *str2 null characters - that's obviously wrong since str2 of null. It also performed final unnecessary increments of str1 and str1, which I've

Re: strncasecmp

2015-11-24 Thread William A Rowe Jr
On Tue, Nov 24, 2015 at 10:07 AM, Mikhail T. wrote: > On 24.11.2015 10:08, William A Rowe Jr wrote: > > As long as this function is promoted for fast ASCII-specific token > recognition and has no other unexpected equalities, it serves a useful > purpose. > > Because of

Re: strncasecmp

2015-11-24 Thread Mikhail T.
On 24.11.2015 10:08, William A Rowe Jr wrote: > As long as this function is promoted for fast ASCII-specific token > recognition and has no other unexpected equalities, it serves a useful > purpose. Because of this, I'd suggest renaming it to something, that emphasizes it being ASCII-only.

Re: strncasecmp

2015-11-24 Thread Yann Ylavic
On Tue, Nov 24, 2015 at 4:12 AM, Mikhail T. wrote: > On 23.11.2015 19:43, Yann Ylavic wrote: > >> That's expected (or at least no cared about in this test case). We simply >> want res to not be optimized out, so print it before leaving, without any >> particular

Re: strncasecmp

2015-11-24 Thread Yann Ylavic
On Tue, Nov 24, 2015 at 6:10 AM, Mikhail T. wrote: > > Attached is the same program with one more pair of > functions added (and an easy way to add more "candidates" to the > main-driver). I changed the FOR-loop define to obtain repeatable results: This test program

Re: strncasecmp

2015-11-24 Thread William A Rowe Jr
On Tue, Nov 24, 2015 at 6:40 AM, Jim Jagielski wrote: > It really depends on the OS and the version of the OS. In > my test cases on OSX and CentOS5 and centOS6, I see > measurable improvements. > Part of the reason for your differences... on this console here I have; $ set |

Re: strncasecmp

2015-11-24 Thread Jim Jagielski
It really depends on the OS and the version of the OS. In my test cases on OSX and CentOS5 and centOS6, I see measurable improvements. > On Nov 23, 2015, at 3:12 PM, Christophe JAILLET > wrote: > > Hi Jim, > > Do you have done some benchmark and have results to

Re: strncasecmp

2015-11-23 Thread Christophe JAILLET
Hi Jim, Do you have done some benchmark and have results to share? I tried to do some but the benefit of the optimized version is not that clear, at least on my system: gcc 5.2.1 Linux linux 4.2.0-18-generic #22-Ubuntu SMP Fri Nov 6 18:25:50 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Re: strncasecmp

2015-11-23 Thread Yann Ylavic
Hi Christophe, On Mon, Nov 23, 2015 at 9:12 PM, Christophe JAILLET wrote: > > I tried to do some but the benefit of the optimized version is not that > clear, at least on my system: >gcc 5.2.1 >Linux linux 4.2.0-18-generic #22-Ubuntu SMP Fri Nov 6 18:25:50

Re: strncasecmp

2015-11-23 Thread Yann Ylavic
I modified your test program a bit (to measure time from it, see attached), tried with -O{2,3,s}, and except -Os I always have better results with the "optimized" version, eg: $ ./a-O3.out 0 15000 xcxcxcxcxcxcxcxcxcxcwwaa xcxcxcxcxcxcxcxcxcxcwwaa 0

Re: strncasecmp

2015-11-23 Thread Yann Ylavic
Please note that the changes in ap_str[n]casecmp(), ie: ++ps1; ++ps2; was a first try/change which (obviously) did nothing. You may ignore it. On Mon, Nov 23, 2015 at 11:43 PM, Yann Ylavic wrote: > with attachment... > > On Mon, Nov 23, 2015 at 11:42 PM,

Re: strncasecmp

2015-11-23 Thread Yann Ylavic
with attachment... On Mon, Nov 23, 2015 at 11:42 PM, Yann Ylavic wrote: > I modified your test program a bit (to measure time from it, see > attached), tried with -O{2,3,s}, and except -Os I always have better > results with the "optimized" version, eg: > > $ ./a-O3.out 0

Re: strncasecmp

2015-11-23 Thread Mikhail T.
On 23.11.2015 23:14, William A Rowe Jr wrote: > L1 cache and other direct effects of cpu internal optimization. Just what I was thinking. Attached is the same program with one more pair of functions added (and an easy way to add more "candidates" to the main-driver). I changed the FOR-loop define

Re: strncasecmp

2015-11-23 Thread William A Rowe Jr
On Nov 23, 2015 21:12, "Mikhail T." wrote: > > On 23.11.2015 19:43, Yann Ylavic wrote: >> >> No measured difference in my tests, I guess it depends on likelyhood to fail/succeed early in the string or not. > > ? I don't see, where it wins anything -- but I do see, where

Re: strncasecmp

2015-11-23 Thread Mikhail T.
On 23.11.2015 19:05, Yann Ylavic wrote: > Here is the correct (new) test, along with the diff wrt the original > (Christophe's) test.c. BTW, if the program measures its own time, should it not use getrusage() instead of gettimeofday()? -mi

Re: strncasecmp

2015-11-23 Thread Yann Ylavic
On Tue, Nov 24, 2015 at 1:07 AM, Mikhail T. wrote: > > BTW, if the program measures its own time, should it not use getrusage() > instead of gettimeofday()? Well, it measures the time spent in the relevant code, with a monotonic clock, that should be fair enough. We

Re: strncasecmp

2015-11-23 Thread Yann Ylavic
On Mon, Nov 23, 2015 at 11:42 PM, Yann Ylavic wrote: > except -Os I always have better > results with the "optimized" version To reach better performances with -Os, we could possibly use: int ap_strcasecmp(const char *s1, const char *s2) { const unsigned char *ps1 =

Re: strncasecmp

2015-11-23 Thread Mikhail T.
On 23.11.2015 17:43, Yann Ylavic wrote: > with attachment... There is a mistake somewhere in the optimized version: ./o 1 1 aa1a 0 Optimized (nb=1, len=0) time = 0.611311 : res = 0 The result should not be zero. Indeed, the string.h version is correct: ./o 0

Re: strncasecmp

2015-11-23 Thread Mikhail T.
On 23.11.2015 19:05, Yann Ylavic wrote: > while (ucharmap[*ps1] == ucharmap[*ps2++]) { > if (*ps1++ == '\0') { > return (0); > } > } > return (ucharmap[*ps1] - ucharmap[*--ps2]); Is there really a gain in inc- and decrementing this way? Would not it be

Re: strncasecmp

2015-11-23 Thread Yann Ylavic
FWIW, a new version using clock_gettime() instead of gettimeofday(). Same/Comparable results for optimized vs string.h's (the former wins but with -Os). On Tue, Nov 24, 2015 at 1:43 AM, Yann Ylavic wrote: > On Tue, Nov 24, 2015 at 1:24 AM, Mikhail T.

Re: strncasecmp

2015-11-23 Thread Yann Ylavic
On Tue, Nov 24, 2015 at 12:46 AM, Mikhail T. wrote: > On 23.11.2015 17:43, Yann Ylavic wrote: > > with attachment... > > There is a mistake somewhere in the optimized version: My bad, I somehow corrupted the original ap_str[n]casecmp() functions. Here is the correct

Re: strncasecmp

2015-11-23 Thread Yann Ylavic
On Tue, Nov 24, 2015 at 1:24 AM, Mikhail T. wrote: > > Is there really a gain in inc- and decrementing this way? Would not it be > easier to read with the explicit increments -- and, incidentally, no > decrements at all? No measured difference in my tests, I guess it

Re: strncasecmp

2015-11-23 Thread Mikhail T.
On 23.11.2015 19:43, Yann Ylavic wrote: > No measured difference in my tests, I guess it depends on likelyhood to > fail/succeed early in the string or not. ? I don't see, where it wins anything -- but I do see, where it loses a little... > That's expected (or at least no cared about in this test

Re: strncasecmp

2015-11-23 Thread Marion & Christophe JAILLET
I just made a small application which takes as command line parameters the number of iteration to run, which version of the algorithm to use, the 2 strings to compare and the length to compare (or 0 for the non 'n' versions) Compiled using gcc -O3 test.c Tested using

Re: strncasecmp

2015-11-20 Thread William A Rowe Jr
I'm +1 if you are suggesting an ascii-only implementation, and by all means introduce both an ap_ and apr_ flavor at the same time. E.g. apr[r]_ascii_str[n]casecmp(). All characters <'A' || >'Z' && <'a || >'z' should be compared by identity. I'm not sure which OS/X implementation you are

Re: strncasecmp

2015-11-20 Thread William A Rowe Jr
Pay special attention to; The *strncasecmp*() function shall compare, *while ignoring differences in case*, not more than *n* bytes from the string pointed to by *s1* to the string pointed to by *s2*. In the POSIX locale, *strcasecmp*() and *strncasecmp*() shall *behave as if the strings had

Re: strncasecmp

2015-11-20 Thread Christophe JAILLET
+1 Le 20/11/2015 18:17, Jim Jagielski a écrit : We use str[n]casecmp quite a bit. The rub is that some platforms use a sensible implementation (such as OSX) which uses a upper-lowercase map and is v. fast, and others use a brain-dead version which does an actual tolower() of each char in the

Re: strncasecmp

2015-11-20 Thread Yann Ylavic
+1 On Fri, Nov 20, 2015 at 6:17 PM, Jim Jagielski wrote: > We use str[n]casecmp quite a bit. The rub is that some > platforms use a sensible implementation (such as OSX) which > uses a upper-lowercase map and is v. fast, and others > use a brain-dead version which does an

Re: strncasecmp

2015-11-20 Thread Jim Jagielski
Implemented in r1715401 If people want to nit-pick about naming and wish to rename it to something else, be my guest. > On Nov 20, 2015, at 1:03 PM, Yann Ylavic wrote: > > +1 > > On Fri, Nov 20, 2015 at 6:17 PM, Jim Jagielski wrote: >> We use

Re: strncasecmp

2015-11-20 Thread William A Rowe Jr
At first glance this seems to meet the POSIX definition in the POSIX context. Just want to be careful about using this for non-posix applications and your doxygen seems to cover this. Looks good to me. Implemented in r1715401 If people want to nit-pick about naming and wish to rename it to

Re: strncasecmp

2015-11-20 Thread Christophe JAILLET
Le 20/11/2015 18:17, Jim Jagielski a écrit : Ideally, it would be in apr +1 This could also be even more interesting, because of apr_table_ functions. CJ