Jun
4th
Wed
4th
Counting Characters in UTF-8 Strings Is Fast
“So, on my CPU, the C version of strlen took about 28% less time than the built-in inlined one for this long string; it only uses two registers instead of the three used by the built-in inlined one (the one that uses repnz scasb); and they both seem to be about 12 bytes. I don’t know why GCC inlines the worse one. Most likely it used to be faster than whatever GCC generated at the time and hasn’t been revisited.”