Wednesday, July 01, 2020

Re: strlcpy version speed tests?

Are you clinging to traditions for some purpose? I gave two different
versions. strlcpy3 is clearly more easily understood and even slightly
faster and strlcpy4 which sets up the following workhorse lines which
through timing the functions is hands down faster on my Xeon chips:


strlcpy4:
while (--nleft != 0)
if ((*++dst = *++src) == '\0')
...

the others:

while (--nleft != 0)
if ((*dst++ = *src++) == '\0')

...


I spoke to my favorite university computer science professor who said
++n is faster than n++ because the function needs to store the initial
value, increment, then return the

stored value in the former case,

while the later merely increments, and returns the value. Apparently,
he is still correct on modern hardware.

--
-Luke

No comments:

Post a Comment