Note that there are some explanatory texts on larger screens.

plurals
  1. POHuge performance slowdown - vectors the problem?
    text
    copied!<p>This part of my code is meant to take an irregularly-shaped outline of <code>Tile</code> objects and loop through creating a ring and decreasing the height value of the tiles in the ring while expanding the ring each time to include those tiles just outside the previous ring (does that make sense?). What I find, however, is that I'm getting massive performance slowdowns, with each loop absurdly slower than the one before. Why could this be?</p> <p>I was thinking it might be because of the noobish <code>oldEdge = theEdge;</code> and comparable lines (both are vectors, I'm assigning one to the other). But even so, I don't understand the huge performance drop. Maybe I'm doing something obviously silly. Can someone set me straight?</p> <p>Note that <code>oldEdge</code>, <code>theEdge</code> and <code>newEdge</code> are all <code>vector&lt;Tile*&gt;</code>s.</p> <pre><code>int decrease = 1; while(decrease &lt; 10) { cout &lt;&lt; "Trying to smooth!\n"; //First, modify the new edge. int newHeight = 70 - decrease; cout &lt;&lt; "Height at: " &lt;&lt; newHeight &lt;&lt; endl; for(int i = 0; i &lt; newEdge.size(); ++i) { newEdge[i]-&gt;SetHeight(newHeight); } //Increment decrease. decrease += 1; //Set the oldEdge and theEdge variables. oldEdge = theEdge; theEdge = newEdge; newEdge.clear(); //Finally, find the new edge. cout &lt;&lt; "Finding new edge!\n"; for(int i = 0; i &lt; theEdge.size(); ++i) { //cout &lt;&lt; "Checking a tile's neighbors!\n"; for(int j = 0; j &lt; theEdge[i]-&gt;m_AdjacentTiles.size(); ++j) { bool valid = true; //Is this neighbor in theEdge? //cout &lt;&lt; "Is this neighbor in theEdge?\n"; for(int k = 0; k &lt; theEdge.size(); ++k) { if(theEdge[i]-&gt;m_AdjacentTiles[j] == theEdge[k]) { valid = false; break; } } //If not, is it in oldEdge? if(valid) { //cout &lt;&lt; "Is this neighbor in oldEdge?\n"; for(int k = 0; k &lt; oldEdge.size(); ++k) { if(theEdge[i]-&gt;m_AdjacentTiles[j] == oldEdge[k]) { valid = false; break; } } } //If neither, it must be valid for continued expansion. if(valid) { newEdge.push_back(theEdge[i]-&gt;m_AdjacentTiles[j]); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload