2 ms·
1) Yes, about 4-6 times faster than byte-by-byte loop "in the long run", but not for short strings. 2) Mostly not. gcc and clans don't vectorize "search loops"
by BeeOnRope 7y ago
1) Yes, about 4-6 times faster than byte-by-byte loop "in the long run", but not for short strings.
2) Mostly not. gcc and clans don't vectorize "search loops" i.e. loops that terminate early based on some condition. These loops are tricky to vectorize at least partly because of the reading-beyond-the-end issue mentioned in the accepted answer. icc does vectorize some search loops, not sure if it would do a good job on this one. I'm not sure about MSVC, but it's usually way behind on everything optimization related so I think we can assume not.
3. Yes definitely. glibc has such implementations for popular platforms like x86, so this code isn't actually being used on your PC say.