title: operator new[] extremely slow on MSVC debug
body: <p>In my application startup there is a quite little allocation of memory for a 3-ary pointer structure.</p>
  <pre><code>#define N_1 1024
  #define N_2 32
  #define N_3 1024
  
  #include &lt;boost/date_time/posix_time/posix_time.hpp&gt;
  
  typedef uint16_t counts;
  typedef counts * spectra;
  typedef spectra * line;
  typedef line * pline;
  typedef pline * cube;
  
  void foo()
  {
      cube cb = new pline[N_3];
  
      for (int n3 = 0; n3 &lt; N_3; n3++)
      {
          boost::posix_time::ptime tic = boost::posix_time::microsec_clock::local_time();
  
          line ln = new spectra[N_2];
  
          for (int n2 = 0; n2 &lt; N_2; n2++)            
          {
              ln[n2] = new counts[N_1]();
          }
  
          cb[n3] = &amp;(ln);
  
          boost::posix_time::ptime toc = boost::posix_time::microsec_clock::local_time();
          boost::posix_time::time_duration dur = toc - tic;
          std::cout &lt;&lt; n3 &lt;&lt; &quot; line allocated in &quot; &lt;&lt; dur.total_microseconds() &lt;&lt; &quot; us\n&quot;;
      }
  }
  </code></pre>
  <p>So we got an allocation of <code>sizeof(counts)*N_1*N_2*N_3</code> = <code>2*1024*1024*32</code> bytes, resulting in <code>64 MB</code> on the heap.</p>
  <p>Problem is, building in <em>Visual Studio DEBUG</em> mode only, about the enormous time consumed during <code>foo()</code> execution.
  In particular, this is a part of a strange (afaik) log:</p>
  <blockquote>
  <p>0 line allocated in 0 us</p>
  <p>1 line allocated in 0 us</p>
  <p>.........................</p>
  <p>104 line allocated in 0 us</p>
  <p>105 line allocated in <strong>1000002</strong> us</p>
  <p>106 line allocated in 0 us</p>
  <p>.........................</p>
  </blockquote>
  <p>In <em>Release</em> mode, everything's running smooth. Any insight ?</p>
  <p><strong>EDIT:</strong></p>
  <p>Since most of you pointed out my wrong usage of <code>boost::posix_time::second_clock</code>, now replaced by <code>boost::posix_time::microsec_clock</code>, I'd like to highlight the fact that the real issue is on <code>new[]</code> performance while debugging, not on which is the best <em>tic-toc</em> tool.</p>