title: std::fstream buffering vs manual buffering (why 10x gain with manual buffering)?
body: <p>I have tested two writing configurations:</p>
  
  <ol>
  <li><p>Fstream buffering:</p>
  
  <pre><code>// Initialization
  const unsigned int length = 8192;
  char buffer[length];
  std::ofstream stream;
  stream.rdbuf()-&gt;pubsetbuf(buffer, length);
  stream.open("test.dat", std::ios::binary | std::ios::trunc)
  
  // To write I use :
  stream.write(reinterpret_cast&lt;char*&gt;(&amp;x), sizeof(x));
  </code></pre></li>
  <li><p>Manual buffering:</p>
  
  <pre><code>// Initialization
  const unsigned int length = 8192;
  char buffer[length];
  std::ofstream stream("test.dat", std::ios::binary | std::ios::trunc);
  
  // Then I put manually the data in the buffer
  
  // To write I use :
  stream.write(buffer, length);
  </code></pre></li>
  </ol>
  
  <p>I expected the same result...</p>
  
  <p>But my manual buffering improve performance by a factor of 10 to write a file of 100MB, and the fstream buffering does not change anything compared to the normal situation (without redefining a buffer).</p>
  
  <p>Does someone has an explanation of this situation ?</p>
  
  <p>EDIT :
  Here are the news : a benchmark just done on a supercomputer (linux 64-bit architecture, lasts intel Xeon 8-core, Lustre filesystem and ... hopefully well configured compilers) 
  <img src="https://i.stack.imgur.com/NO8Pm.png" alt="benchmark">
  (and I don't explain the reason of the "resonance" for a 1kB manual buffer...)</p>
  
  <p>EDIT 2 :
  And the resonance at 1024 B (if someone has an idea about that, I'm interested) :
  <img src="https://i.stack.imgur.com/pknmv.png" alt="enter image description here"></p>