Denial of responsibility
I am looking for the fastest way to identify the first occurrence of a given byte in a byte buffer.
This is similar to finding the first character in a string, except that:
- the byte buffer is not NUL terminated, instead I have an explicit length (and possibly inline NUL characters)
- the byte buffer is not allocated in
stringor vector, I only get a slice (aka, pointer and length)
Basic solution:
size_t search(char const* buffer, size_t length, char c) {
return std::find(buffer, buffer + length, c) - buffer;
}
, Godbolt (-O2 -msse2 -mavx) , , , .
?
: .
. x86_64 Linux, , .