c++ - Performance - iterating over vector with iterator or pointer? -


i'm writing application needs perform can be. i'm using vs2012 ide (and compiler).

i've noticed, i'm iterating on vectors, pointer solution in contrast iterator, quicker in terms of speed. why that? mean, iterator basicly same thing. should @ least.

take @ example:

std::vector<int> v; (std::vector<int>::iterator = v.begin(); != v.end(); it++) {     // stuff *it }  (int* = &v[0], <= &v[v.size()-1]; i++) {     // stuff *i } 

is there optimization needed compiler? i'm using standard settings, -o2 enabled. in advance.

edit: i'm compiling in release, , running ctrl+f5 (without debugging is).

edit2: actual source-code implementation of quicksort. here link full source, short check out.

i'm writing application needs perform can be.

then grab profiler , real bottlenecks are. in optimized code (release mode), of course.

-o2 not in vs2012: there several #defines manipulate behavior of standard container iterators wrt bounds checking , other security checks. might want them ("checked iterators" , "secure scl" might lead right sites) , set them accordingly.

but doubt iteration on containers bottleneck, there other sections of code more sensitive performance issues.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -