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. _______________________________________________ help-gplusplus mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-gplusplus
