On Sun, Aug 03, 2003 at 02:37:23PM +0200, Andr� Malo wrote: > * Joe Orton wrote: > > > I understand the need for a strcasecmp replacement, but are the > > strcmp/!strcmp replacements just for consistency? On some platforms > > strcmp is an optimised asm inline so unless there's a good reason to > > tempt people away from strcmp I'd leave apr_streq/strneq out. > > Attached is a quick benchmark with very interesting results. Some other > compiler tests would be helpful, of course. > The main result of this one is: As long as the function is inlined and an > optimizer is turned on, it's reasonably faster than strcmp.
That benchmark is rigged :) It only compares against the strcmp in libc.so due to the missing #include <string.h>. I'd always bet on the inline asm over C code... $ gcc -O2 -DINLINE -o streq streq.orig.c && ./streq iterations: 1000000000 [01/05] streq: 4 sec [02/05] streq: 5 sec [03/05] streq: 4 sec [04/05] streq: 4 sec [05/05] streq: 4 sec [average] streq: 4.2 sec [01/05] !strcmp: 16 sec [02/05] !strcmp: 17 sec [03/05] !strcmp: 19 sec [04/05] !strcmp: 17 sec [05/05] !strcmp: 16 sec [average] !strcmp: 17 sec You have new mail $ diff -u streq.orig.c streq.c --- streq.orig.c 2003-08-03 13:51:40.000000000 +0100 +++ streq.c 2003-08-03 13:52:36.000000000 +0100 @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <time.h> +#include <string.h> #define LEN (1024 * 1024) #define ITER (1000 * 1000 * 1000) $ gcc -O2 -DINLINE -o streq streq.c && ./streq iterations: 1000000000 [01/05] streq: 4 sec [02/05] streq: 4 sec [03/05] streq: 4 sec [04/05] streq: 4 sec [05/05] streq: 4 sec [average] streq: 4 sec [01/05] !strcmp: 2 sec [02/05] !strcmp: 3 sec [03/05] !strcmp: 3 sec [04/05] !strcmp: 3 sec [05/05] !strcmp: 2 sec [average] !strcmp: 2.6 sec
