template <typename T>
int custom_memcmp(const T* a, const T* b, std::size_t n);
Would this be faster than C’s memcmp?
If sizeof(T) != 1: it will perform less iterations and it can compare the values as their actual types. For example I’d except comparing two ‘long long’s directly to be faster than comparing two 8-byte buffers.
memcmpis usually a compiler intrinsic, so will be optimised to be about as efficient as it’s possible to get (will be vectorised, inlined, etc.).So you almost certainly won’t beat it. But of course, if you want to know for sure, then just profile!