This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Advice on iterator vs. index efficiency
- From: me22 <me22 dot ca at gmail dot com>
- To: "Neal Becker" <ndbecker2 at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 5 Oct 2007 21:50:41 -0400
- Subject: Re: Advice on iterator vs. index efficiency
- References: <fe5s5c$fdm$1@sea.gmane.org>
On 05/10/2007, Neal Becker <ndbecker2@gmail.com> wrote:
> Based on advice from some time back, I write algorithms to use iterators
> rather than index-based loops. Often, this requires jumping through
> considerable hoops.
>
> I'm just wondering, with current gcc loop optimizations, it this advice
> still relevant?
>
> Is there (in general) a difference in speed for these 2 styles? What about
> if the containers are multi-dimensional and loops are nested?
I remember seeing that for the simple begin-to-end loop over a vector,
gcc actually ends up compiling the iterator and index versions to the
exact same code.
In general, I'd say that if there would be a difference, the iterator
one might be faster as moving to the "next" might be simpler than
descending some data structure to an index.
Of course, I have no idea how pointers versus indices affects alias
analysis, or how much importance you'd place in the generality of
iterators.
~ Scott
--
La vendetta à un piatto che va servito freddo
Sed quis custodiet ipsos custodes?