Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] memcmp versus strncmp

On Fri Dec 09, 2005 at 23:56:14 +1100, Ken Foskey wrote:
>This is an unexpected statistic...
>Subroutine using massive number of matches:
> strcmp(x,y) 1.87 seconds
> strncmp(x,y,6) 1.63 seconds
> memcmp(x,y,6) 5.85 seconds
>Ignoring the other code it is a huge overhead for using memcmp on Ubuntu
>I386 as opposed to strncmp.
>I would not have expected this, any ideas?

Umm, are those number meant to be u-seconds? Or is that for doing a run
of many times?

I'm guessing that for small n memcmp is ineffecient because it is optomised
for large n, where as you can't optimise str{n}cmp for large n, so for small
n it is faster.