title: Mysterious slowdown when adding doubles to dynamic vector in C++
body: <p>I am experiencing some unknown slowdown when adding doubles to a very large dynamic vector of doubles in C++. </p>
  
  <p>As seen below, it appears that slowdown occurs specifically due to adding a double that was calculated from a long-winded sum of cos and sin functions.</p>
  
  <p>When only A_temp1 is added to the dynamic vector, there is no slowdown:</p>
  
  <pre><code>    for(int i=0;i&lt;=imax;i++){
      // neither of these cause slowdown on their own
         A_temp1 = pi;
         A_temp2 = [long-winded sum of sin and cos operations]; 
      // no slowdown if only A_temp1 is  added
          A_dyn_vec[i] = A_temp1; 
      }
  </code></pre>
  
  <p>However, when A_temp2 is added to the vector, there is significant slowdown:</p>
  
  <pre><code>    for(int i=0;i&lt;=imax;i++){
      // neither of these cause slowdown on their own
         A_temp1 = pi;
         A_temp2 = [long-winded sum of sin and cos operations]; 
      // significant slowdown 
          A_dyn_vec[i] = A_temp1 + A_temp2; 
      }
  </code></pre>
  
  <p>Also, when both are merged into a single A_temp value, there the same significant slowdown seen:</p>
  
  <pre><code>    for(int i=0;i&lt;=imax;i++){
      // neither of these cause slowdown on their own
         A_temp = pi + [long-winded sum of sin and cos operations]; 
      // significant slowdown 
          A_dyn_vec[i] = A_temp;
      }
  </code></pre>
  
  <p>In summary, for some reason, adding A_temp1 does not cause slowdown, but A_temp2 does, even though they are both doubles. </p>
  
  <p>A_temp2 specifically came from a function involving a long-winded sum of cos and sin functions. Perhaps something in the nature of how this number is stored is causing the issue, but I cannot figure out exactly why.  </p>
  
  <p>I would greatly appreciate if anyone has any input on why the slowdown is happening in this situation and how to avoid it.</p>
  
  <p>Thank you!</p>