Created
October 4, 2018 11:28
-
-
Save dpk/2beb8e3813bd6b34a6dd67b37a9b2134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
unsigned long utf8_strlen(unsigned char *s) { | |
unsigned long len = 0; | |
s--; | |
while (*++s) { | |
len += !(*s >> 7) || (*s >> 6); | |
} | |
return len; | |
} | |
int main() { | |
for (int i = 0; i < 10000000; i++) { | |
utf8_strlen("hello world"); | |
utf8_strlen("héllo world"); | |
utf8_strlen("héłlo world"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment