C++ vector performance: iterator access versus brackets operator access -


i'm wondering whether iterator outperform brackets operator in sequential access setting. consider following code snippets:

// v1.1 (std::vector<int>::const_iterator = v.begin(); != v.end(); ++it) {     do_something(*it); }  // v1.2 (size_t = 0; != v.size(); ++i) {     do_something(v[i]); }  // v1.3 std::vector<int>::const_iterator endit = v.end(); (std::vector<int>::const_iterator = v.begin(); != endit; ++it)      do_something(*it); }  // v1.4 size_t size = v.size(); (size_t = 0; != size; ++i) {     do_something(v[i]); }  // v2.1 (std::vector<int>::iterator = v.begin(); != v.end(); ++it) {     *it = - v.begin(); // iterator arithmetic; expensive or not? }  // v2.2 (size_t = 0; != v.size(); ++i) {     v[i] = i; } 

has ever done benchmark these? (well, depends on compiler; let's take g++ 4.7 or 4.8 instance.) thanks.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -