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 6693391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:58:38+00:00 2026-05-26T05:58:38+00:00

I am fiddling with the performance wizard in VS2010, the one that tests instrumentation

  • 0

I am fiddling with the performance wizard in VS2010, the one that tests instrumentation (function call counts and timing.)

After learning about vectors in the C++ STL, I just decided to see what info I can get about performance of filling a vector with 1 million integers:

#include <iostream>
#include <vector>

void generate_ints();

int main() {
  generate_ints();
  return 0;
}

void generate_ints() {
  typedef std::vector<int> Generator;
  typedef std::vector<int>::iterator iter;
  typedef std::vector<int>::size_type size;

  Generator generator;

  for (size i = 0; i != 1000000; ++i) {
    generator.push_back(i);
  }
}

What I get is: 2402.37 milliseconds of elapsed time for the above. But I learnt that vectors have to resize themselves when they run out of capacity as they are contiguous in memory. So I thought I’d get better performance by making one addition to the above which was:

generate.reserve(1000000);

However this doubles the execution time of the program to around 5000 milliseconds. Here is a screenshot of function calls, left side without the above line of code and right side with. I really don’t understand this result and it doesn’t make sense to me given what I learnt about how defining a vectors capacity if you know you will fill it with a ton is a good thing. Specifying reserve basically doubled most of the function calls.

http://imagebin.org/179302

  • 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. Editorial Team
    Editorial Team
    2026-05-26T05:58:39+00:00Added an answer on May 26, 2026 at 5:58 am

    From the screenshot you posted, it looks like you’re compiling without optimization, which invalidates any benchmarking you do.

    You benchmark when you care about performance, and when you care about performance, you press the “go faster” button on the compiler, and enable optimizations.

    Telling the compiler to go slow, and then worrying that it’s slower than expected is pointless. I’m not sure why the code becomes slower when you insert a reserve call, but in debug builds, a lot of runtime checks are inserted to catch more errors, and it is quite possible that the reserve call causes more such checks to be performed, slowing down the code.

    Enable optimizations and see what happens. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been fiddling with a program for about 20 minutes and I found that
After much fiddling, I've managed to install the right ODBC driver and have successfully
Is there an efficient way that doesn't require too much fiddling (I can cope
I am currently reading a book about bit fiddling and the following formula appears:
From some brief fiddling about, I find I get an error when overriding superclass
Heya. Finally, after a lot of fiddling, I got a .rc-loaded context menu for
Edit: after much fiddling, it seems urlgrabber succeeds where urllib2 fails, even when telling
I've been fiddling around with drupal theming quite succesfully (or at least, that's what
After fiddling around with an issue I am having I have come to this
I am fiddling around with a dialog that pops up and displays an alarm

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.