Performance: Iterating a vector in a loop..
- From: Mark Ingram <mark.ingram@xxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 May 2005 12:26:39 +0100
Hi, im having a discussion with a colleague about iterating through a vector in a loop.
my current way is:
vector<MyType>::iterator itLoop;
for (itLoop = vec.begin(); itLoop != vec.end(); itLoop++)
{
itLoop->DoSomething();
}But he was saying its slow because .begin() and .end() are called every loop.
I know that the function is called every iteration, but was under the impression that STL is highly optimised in dealing with things like this, so it shouldnt make too much difference.
Can anyone shed any light on this and explain whether or not it really has any speed hits when doing that, or, if it would be better to re-write the code like this (which i feel is less legible).
vector<MyType>::iterator itLoop, itBegin = vec.begin(), itEnd= vec.end();
for (itLoop = itBegin ; itLoop != itEnd; itLoop++)
{
itLoop->DoSomething();
}Thanks for any info. .
- Follow-Ups:
- Re: Performance: Iterating a vector in a loop..
- From: Tim Roberts
- Re: Performance: Iterating a vector in a loop..
- From: andré m.a
- Re: Performance: Iterating a vector in a loop..
- From: Hendrik Schober
- Re: Performance: Iterating a vector in a loop..
- Prev by Date: Re: How to remove linking warning LNK4089
- Next by Date: Re: Performance: Iterating a vector in a loop..
- Previous by thread: Number of handles are increasing at 500 per seconds...
- Next by thread: Re: Performance: Iterating a vector in a loop..
- Index(es):
Relevant Pages
|
Loading