Hi Mat,
>
> how does a direct for/while loop implementation compare speed wise to
> calling strlen & memcpy?
It's about twice as fast to use strlen/memcpy. The direct implementation
I used for comparison:
const char *orig_src = src;
if (len) {
while (*src != '\0' && --len) {
*dst++ = *src++;
}
*dst = '\0';
}
return (src - orig_src) + strlen(src);
I modified the unit test to run a bunch of iterations with some more
string sizes and to take performance samples during the strlcpy test.
gperftools showed that the direct code spent 57.39% of execution time
inside l_strlcpy and the strlen/memcpy technique spent 16.06% of
execution time inside l_strlcpy. Turning off the profiling stuff and
just using 'time', direct took 53.973 seconds and strlen/memcpy took
25.176 seconds of user time.
Interesting, seems counter-intuitive since we're walking the string
twice. I went ahead and applied the original patch 2 + 3. Much
appreciated!
Regards,
-Denis