On Wed, Jul 01, 2020 at 07:05:02AM -0500, Luke Small wrote: > 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.
If you really care about speed, you should probably look into an arch/ asm version instead