Originally Posted by
SixDegrees
Note, also, that your tests are not valid. In the STL case, you call list.end() on each iteration of the loop, incurring an unnecessary function call.
Tried to use
QList<int>::iterator i;
QList<int>::iterator end = list.end();
for(i = list.begin(); i != end; ++i)
sum += *i;
QList<int>::iterator i;
QList<int>::iterator end = list.end();
for(i = list.begin(); i != end; ++i)
sum += *i;
To copy to clipboard, switch view to plain text mode
and processing time decreased to 84 ms. But if try
for(int i = 0; i < list.size(); i++)
for(int i = 0; i < list.size(); i++)
To copy to clipboard, switch view to plain text mode
or
int size = list.size();
for(int i = 0; i < size; i++)
int size = list.size();
for(int i = 0; i < size; i++)
To copy to clipboard, switch view to plain text mode
results are the same. It seems that compiler optimizes this function call.
Bookmarks