
Originally Posted by
wysota
I'm pretty certain std::reverse uses the same algorithm your newReverse does
Actually I just added a stdReverseList to the mix
{
std::reverse(reversedList.begin(), reversedList.end());
return reversedList;
}
static inline QStringList stdReverseList(const QStringList &list)
{
QStringList reversedList = list;
std::reverse(reversedList.begin(), reversedList.end());
return reversedList;
}
To copy to clipboard, switch view to plain text mode
Result:
2000000 iterations of oldReverseList in 13 seconds
2000000 iterations of newReverseList in 7 seconds
2000000 iterations of stdReverseList in 14 seconds
My totaly unscientific guess to explain the result, would be that access via the iterators (as needed by std::reverse) is slower than access via operator[]...
Bookmarks