You aren't counting right. The standard C while loop version does
~N reads and N writes, where N is the length of the string, plus N
tests and N jumps.
A strlen will do ~N reads, N tests, and N jumps. Even a slightly
optimized memcpy (no tricks with floating point registers or anything
like that, just longword moving) will do ~N/4 reads, N/4 writes, N/4
tests, and N/4 jumps. Total reads, tests, and jumps are up by 25%,
but writes are down by 75%. It is nowhere near double the number
of instructions. If the memcpy unrolls the loop, the strlen + memcpy
version is likely to use less instructions.
--Tim Smith
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu