Re: [xml] RAW && NXT with strncmp()



On Wed, 2003-10-01 at 15:50, Daniel Veillard wrote:

  That I was looking at it this yesterday actually but I don't feel
that confident about such a change, yet ...

The libc string functions tend to be highly optimized.

Time for informal benchmarking...

[breese stellifer:/home/breese/junk] gcc --version | head -1
gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
[breese stellifer:/home/breese/junk] uname -a
Linux stellifer 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386
GNU/Linux
[breese stellifer:/home/breese/junk] cat compare.c
#include <string.h>
int main(void)
{
  int i;
  int z;
  char buffer[64] = "xmlns";

  for (i = 0; i < 1000000000; ++i) {
#if USE_STRNCMP
    if (strncmp(buffer, "xmlns", sizeof(buffer)) == 0)
      z = 1;
#else
    if (buffer[0] == 'x' && buffer[1] == 'm' &&
        buffer[2] == 'l' && buffer[3] == 'n' &&
        buffer[4] == 's')
      z = 1;
#endif
  }
  return 0;
}
[breese stellifer:/home/breese/junk] gcc -O2 compare.c
[breese stellifer:/home/breese/junk] time ./a.out
4.560u 0.040s 0:04.85 94.8%     0+0k 0+0io 65pf+0w
[breese stellifer:/home/breese/junk] gcc -DUSE_STRNCMP -O2 compare.c
[breese stellifer:/home/breese/junk] time ./a.out
0.930u 0.000s 0:01.03 90.2%     0+0k 0+0io 66pf+0w

I get roughly the same results if I change the content of 'buffer'.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]