So I've got this mess of code that relies heavily on STL vectors. I'm currently using the .at(n) method to iterate through the vectors. I've stuck with .at(n) because I frequently start iterating at the second or third element and sometimes iterate backwards. Using .at(n) provides a little more consistency to my loops, relying on my for() parameters to specify the ordering of the loop. Should I be using the explicit vector iterator? Is it faster? It's claimed here that both methods are O(1).
I just ran my code under the GlowCode profiler and it claims that a sizable amount of my execution time is spent in .at(n).
3 comments:
You can believe the claims for performance of the STL. They are generally considered functional requirements. So, it is definitely fast.
Why don't you use iterators? With vectors, I believe you can use both forward_iterator (just "iterator") and reverse_iterator. So, your loops should be consistent.
I suppose if you need to iterate in strange fashion, you may not want to use iterators, but I don't know that for sure. Otherwise, I would recommend them.
Hmmmm... Are you profiling debug code, so that range checking is left in your .at(n) inline?
Yep. That (debug code) would explain it precisely. I'll just stick with .at(n).
Post a Comment