title: Which bottleneck is hit using printf on > 65KB strings?
body: <p>This program prints 65k bytes per line.</p>
  
  <p>I measure the throughput with <code>./a.out | pv &gt;/dev/null</code> and get around 3 GB/s.</p>
  
  <p>As soon as I change the line length to 70k, the throughput drops to ~ 1 GB/s.</p>
  
  <p><strong>Which bottleneck</strong> (CPU cache, libc idiosynchrasy, etc.) <strong>am I hitting here?</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #define LEN 65000     // high throughput
  // #define LEN 70000  // low throughput
  
  int main ()
  {
    char s[LEN]; memset(s, 'a', LEN-1); s[LEN-1] = '\0';
  
    while (1)
      printf ("%s\n", s);
  }
  </code></pre>
  
  <p><strong>Update:</strong> I'm running this on Ubuntu 12.04 64-bit, which has EGLIBC 2.15, on a Core i5-2520M.</p>
  
  <p><strong>Update:</strong> <code>puts (s)</code> has the same problem.</p>