Bizarrely slow method
<p>I have a method in my project which when placed into its own program takes mere seconds to run, when run inside the project where it belongs it takes 5 minutes. I have NO idea why. I have tried profiling, taking bits out, changing this and that. I'm stumped. </p>

<p>It populates a vector of integers to be used by another class, but this class is not currently being instantiated. I have checked as much as I can and it does seem as if there really is nothing else happening but the method magically taking longer in one project than it does in another.</p>

<p>The method is run at startup and takes about 5 minutes, or about 3 seconds if run on its own. What could be causing this? Strange project settings? Multithreading stuff that I'm unaware of? (as far as I know there is none in my project anyway unless it's done automatically).</p>

<p>There is a link to the project <a href="http://dl.dropbox.com/u/13519335/D3D10DEMO_1.1.zip" rel="nofollow">here</a>. If anyone could solve this for me I would be so grateful, and as soon as I can will start a bounty for this.</p>

<p>The method is called PopulatePathVectors and runs in Level.cpp. Commenting out the call to the method (in the level constructor) means the program starts up in seconds. The only other class that uses the lists it generates is Agent, but currently none are being instantiated. </p>

<p>EDIT - As requested, here is the code. Although keep in mind that my question is not 'why is the code slow?' but 'why is it fast in one place and slow in my project?'</p>

<pre><code>//parses the text path vector into the engine
void Level::PopulatePathVectors(string pathTable)
{
    // Read the file line by line.
    ifstream myFile(pathTable);

        for (unsigned int i = 0; i &lt; nodes.size(); i++)
        {
            pathLookupVectors.push_back(vector&lt;vector&lt;int&gt;&gt;());

            for (unsigned int j = 0; j &lt; nodes.size(); j++)
            {
                string line;

                if (getline(myFile, line)) //enter if a line is read successfully
                {
                    stringstream ss(line);
                    istream_iterator&lt;int&gt; begin(ss), end;
                    pathLookupVectors[i].push_back(vector&lt;int&gt;(begin, end));
                }
            }
        }
}
</code></pre>

<p>EDIT - I understand that the code is not the best it could be, but that isn't the point here. It runs quickly on it's own - about 3 seconds and that's fine for me. The problem I'm tying to solve is why it takes so much longer inside the project.</p>

<p>EDIT - I commented out all of the game code apart from the main game loop. I placed the method into the initialize section of the code which is run once on start up. Apart from a few methods setting up a window it's now pretty much the same as the program with ONLY the method in, only it STILL takes about 5 minutes to run. Now I know it has nothing to do with dependencies on the pathLookupVectors. Also, I know it's not a memory thing where the computer starts writing to the hard drive because while the slow program is chugging away running the method, I can open another instance of VS and run the single method program at the same time which completes in seconds. I realise that the problem might be some basic settings, but I'm not experienced so apologies if this does disappointingly end up being the reason why. I still don't have a clue why it's taking so much longer.</p>

<p>It would be great if this didn't take so long in debug mode as it means waiting 5 minutes every time I make a change. There MUST be a reason why this is being so slow here. These are the other included headers in the cut down project:</p>

<pre><code>#include &lt;d3d10.h&gt;
#include &lt;d3dx10.h&gt;
#include "direct3D.h"
#include "game.h"
#include "Mesh.h"
#include "Camera.h"
#include "Level.h"

#include &lt;vector&gt;

using namespace std;
</code></pre>

<p>EDIT - <a href="http://dl.dropbox.com/u/13519335/testSolution.zip" rel="nofollow">this</a> is a much smaller self contained project with only a tiny bit of code where the problem still happens.</p>

<p><a href="http://dl.dropbox.com/u/13519335/MethodTest.zip" rel="nofollow">this</a> is also a very small project with the same code where it runs very fast.</p>
