thoth39 wrote:
Ulrich Lauther wrote:
Paulo Matos <[EMAIL PROTECTED]> wrote:
: Hi all,
: I've wanted to know if there was any performance difference between
: using:
: for(vector<int>::const_iterator it = v.begin(); it != v.end(); ++it)
: and
: for(unsigned int k = 0; k < v.size(); ++k)
Try
unsigned int size = v.size();
for (unsigned int k = 0; k < size; ++k)
in your version size() is evaluated size times
Likewise, instead of
for(vector<int>::const_iterator it = v.begin(); it != v.end(); ++it)
try
for(vector<int>::const_iterator it = v.begin(), end = v.end(); it !=
end; ++it)
to avoid calling v.end() every time.
Aren't compilers smart enough yet to in effect do that if it sees there's
nothing done inside the loop that would change the vector's size?
That seems like something an optimizer should do.
_______________________________________________
help-gplusplus mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gplusplus