Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 179485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:24:55+00:00 2026-05-11T14:24:55+00:00

In terms of performance, what would work faster? Is there a difference? Is it

  • 0

In terms of performance, what would work faster? Is there a difference? Is it platform dependent?

//1. Using vector<string>::iterator: vector<string> vs = GetVector();  for(vector<string>::iterator it = vs.begin(); it != vs.end(); ++it) {    *it = 'Am I faster?'; }  //2. Using size_t index: for(size_t i = 0; i < vs.size(); ++i) {    //One option:    vs.at(i) = 'Am I faster?';    //Another option:    vs[i] = 'Am I faster?'; } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:24:56+00:00Added an answer on May 11, 2026 at 2:24 pm

    Why not write a test and find out?

    Edit: My bad – I thought I was timing the optimised version but wasn’t. On my machine, compiled with g++ -O2, the iterator version is slightly slower than the operator[] version, but probably not significantly so.

    #include <vector> #include <iostream> #include <ctime> using namespace std;  int main() {     const int BIG = 20000000;     vector <int> v;     for ( int i = 0; i < BIG; i++ ) {         v.push_back( i );     }      int now = time(0);     cout << 'start' << endl;     int n = 0;     for(vector<int>::iterator it = v.begin(); it != v.end(); ++it) {         n += *it;     }      cout << time(0) - now << endl;     now = time(0);     for(size_t i = 0; i < v.size(); ++i) {         n += v[i];     }     cout << time(0) - now << endl;      return n != 0; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know the difference in terms of performance between these two
What is a better option (in terms of performance): copying a file using fileinputstream
How would you rate each of them in terms of: Performance Speed of development
I have a basic javascript question. In terms of performance, security, maintainability, which would
I was wondering which method would be correct in terms of performance and best
In terms of performance and efficiency, is it better to use lots of small
what is the best solution in terms of performance and readability/good coding style to
I recall having read somewhere that it is better (in terms of performance) to
Which method is better and why, when? In terms of scalability,performance etc which one
What's the best in terms of speed and performance? To call the function each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.