Depending on how many lines (and your compiler) you might be better off sticking with operator== . In Visual C ++ v10, which boils down to calling memcmp via char_traits::compare , which (when optimized) will compare ranges of target bytes in chunks, perhaps as many bytes at a time as fit in the register (4/8 for 32 / 64-bit).
static int __CLRCALL_OR_CDECL compare(const _Elem *_First1, const _Elem *_First2, size_t _Count) {
Meanwhile, std::equal (the nicest alternative) does a byte comparison by byte. Does anyone know if this will be optimized in the same way since they are reverse iterators? In the best case, alignment processing is more complex since the start of the range is not guaranteed to be well aligned.
template<class _InIt1, class _InIt2> inline bool _Equal(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2) { // compare [_First1, _Last1) to [First2, ...) for (; _First1 != _Last1; ++_First1, ++_First2) if (!(*_First1 == *_First2)) return (false); return (true); }
See @greyfade's answer here for some color in GCC.
Steve townsend
source share