title: How to optimise large loops for debug mode
body: <p>I have implemented a pixel mask class used for checking for perfect collision. I am using SFML so the implementation is fairly straight forward:</p>
  
  <p>Loop through each pixel of the image and decide whether its true or false based on its transparency value. Here is the code I have used:</p>
  
  <pre><code>// Create an Image from the given texture
      sf::Image image(texture.copyToImage());
  
      // measure the time this function takes
      sf::Clock clock;
      sf::Time time = sf::Time::Zero;
      clock.restart();
  
      // Reserve memory for the pixelMask vector to avoid repeating allocation
      pixelMask.reserve(image.getSize().x);
  
      // Loop through every pixel of the texture
      for (unsigned int i = 0; i &lt; image.getSize().x; i++)
      {
          // Create the mask for one line
          std::vector&lt;bool&gt; tempMask;
          // Reserve memory for the pixelMask vector to avoid repeating allocation
          tempMask.reserve(image.getSize().y);
  
          for (unsigned int j = 0; j &lt; image.getSize().y; j++)
          {
              // If the pixel is not transparrent
              if (image.getPixel(i, j).a &gt; 0)
                  // Some part of the texture is there --&gt; push back true
                  tempMask.push_back(true);
              else
                  // The user can't see this part of the texture --&gt; push back false
                  tempMask.push_back(false);
          }
          pixelMask.push_back(tempMask);
      }
  
      time = clock.restart();
      std::cout &lt;&lt; std::endl &lt;&lt; "The creation of the pixel mask took: " &lt;&lt; time.asMicroseconds() &lt;&lt; " microseconds (" &lt;&lt; time.asSeconds() &lt;&lt; ")";
  </code></pre>
  
  <p>I have used the an instance of the <code>sf::Clock</code> to meassure time.</p>
  
  <p>My problem is that this function takes ages (e.g. 15 seconds) for larger images(e.g. 1280x720). Interestingly, <strong>only in debug mode</strong>. When compiling the release version the same texture/image only takes 0.1 seconds or less.</p>
  
  <p>I have tried to reduce memory allocations by using the resize() method but it didn't change much. I know that looping through almost 1 million pixels is slow but it should not be 15 seconds slow should it?</p>
  
  <p>Since I want to test my code in debug mode (for obvious reasons) and I don't want  to wait 5 min till all the pixel masks have been created, what I am looking for is basically a way to:</p>
  
  <ul>
  <li>Either optimise the code / have I missed somthing obvious?</li>
  <li>Or get something similar to the release performance in debug mode</li>
  </ul>
  
  <p>Thanks for your help!</p>