pub unsafe fn strlen<T>(ptr: *const T) -> usizewhere
T: ValueType,Expand description
Calculates the length of a null-terminated string pointed to by ptr,
Via specialised instructions, AVX2 if available, then SSE2 then libc’s strlen
§Returns the number of bytes not including the null terminator.
§Safety
This function is unsafe because it dereferences a raw pointer, it will not work on 0 length strings, they MUST be null-terminated.
Uses AVX2 if compiled with flags otherwise SSE2 if available, failng that, libc::strlen.
Interesting benchmarks resuls:
It’s faster than my constant time strlen for dirents for small strings, but after 32 bytes, it becomes slower.
It is also faster than the libc implementation but only for size below 128…?wtf.