
11 Oct
2008
11 Oct
'08
4:10 p.m.
Brandon Kohn wote:
If so, how does direct iteration compare with index operator accesses? I've noticed in my own tests on measuring std::vector accesses that iteration is significantly faster than operator [ ] when you are iterating over the container (presumably due to bounds checking).
operator[] doesn't do bounds checking, unless you have the debug/secure mode of your standard library enabled (which is on by default on MSVC). While access by index is theoretically slower than pointer increments, I'm pretty sure any compiler optimizes the former to the latter.