Just to post my latest findings (of how you can speed up standard algorithms when you work with Qt types)
I simply added the following code:
static inline void swap(QString& a, QString& b)
{
qSwap(a,b);
}
static inline void swap(QString& a, QString& b)
{
qSwap(a,b);
}
To copy to clipboard, switch view to plain text mode
That changed the result to:
2000000 iterations of oldReverseList in 13 seconds
2000000 iterations of newReverseList in 7 seconds
2000000 iterations of stdReverseList in 7 seconds
2000000 iterations of std2ReverseList in 6 seconds
That means you get very easily a great(*) speedup because the STL can now use the optimizations used in qSwap. (Still not as fast as the overall winner here, but the absolute winner in the work/result ratio category :-)
(*): "great" of course only if you do 2000000 million iterations of a reverse list algorithm...which you probably do not do ;-)
but its probably a thing to keep in mind if you find the std algorithms taking too long for your taste :-)
Bookmarks