title: why many small memcpy is faster than one large memcpy?
body: <p>I found that having many small memcpy is faster than having a one large memcpy. I can't understand why it would be the case. Isn't memcpy better at copying a big block of data?</p>
  
  <p>I've tested the following code on both  VC++ 2017 and Intel compiler 2018.</p>
  
  <p>time for one large memcpy: 0.457913 and time for many small memcpy: 0.121063</p>
  
  <pre><code>typedef double tp;
  size_t sz = 100;
  size_t nm = 1000000;
  tp* x = new tp[sz*nm];
  std::vector&lt;tp*&gt; y(nm);
  for (int i = 0; i &lt; nm; ++i)
     y[i] = new tp[sz];
  
  tp*  z1 = new tp[sz*nm];
  std::vector&lt;tp*&gt; z2(nm);
  for (int i = 0; i &lt; nm; ++i)
     z2[i] = new tp[sz];
  
  double currTime, lastTime;
  
  lastTime = omp_get_wtime();
  memcpy((void*)z1, (void*)x, sizeof(tp)*sz*nm);
  currTime = omp_get_wtime();
  std::cout &lt;&lt; "time for one large memcpy: " &lt;&lt; currTime - lastTime &lt;&lt; std::endl;
  
  lastTime = omp_get_wtime();
  for (int i = 0; i &lt; nm; ++i)
      memcpy((void*)z2[i], (void*)y[i], sizeof(tp)*sz);
  currTime = omp_get_wtime();
  std::cout &lt;&lt; "time for many small memcpy: " &lt;&lt; currTime - lastTime &lt;&lt; std::endl;
  
  delete[] x;
  delete[] z1;
  for (int i = 0; i &lt; nm; ++i)
  {
     delete[] y[i];
     delete[] z2[i];
  }
  </code></pre>