strcspn(3) complexity improvement

Brooks Davis brooks at one-eyed-alien.net
Tue Apr 5 23:20:45 PDT 2005


On Tue, Apr 05, 2005 at 08:46:50PM -0700, Matthew Dillon wrote:
> :The real question I have is, how long does the string need to be before
> :this is a win and how much does it hurt for typical string lengths?
> :I've written code with strcspn that needed to perform well, but it was
> :parsing 80-column punch card derived formats.
> 
>      I think the answer is to not use strcspn() in cases where it *really*
>      matters.

Certainly.  strcspn() wasn't worth optimizing out after I replaced the
hand coded crap that used getc to parse files up to 100MB is size and
did a realloc for each character!  That got me a 50% speedup in overall
execution time and the function dropped from #1 to <#50 in the
profiling numbers.  At that point FPU intensive code was at the top
where it belonged.

My main point was to avoid a purely theoretical "optimization".

-- Brooks

-- 
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20050405/95048441/attachment.bin


More information about the freebsd-current mailing list