Typical strlen() traverse from first character till it finds \0.
This requires you to traverse each and every character.
In algorithm sense, its O(N).
Is there any faster way to do this where input is vaguely defined.
Like: length would be less than 50, or length would be around 200 characters.
I thought of lookup blocks and all but didn’t get any optimization.
Actually, glibc’s implementation of
strlenis an interesting example of the vectorization approach. It is peculiar in that it doesn’t use vector instructions, but finds a way to use only ordinary instructions on 32 or 64 bits words from the buffer.