Which bottleneck is hit using printf on > 65KB strings?

Viewed 344

This program prints 65k bytes per line.

I measure the throughput with ./a.out | pv >/dev/null and get around 3 GB/s.

As soon as I change the line length to 70k, the throughput drops to ~ 1 GB/s.

Which bottleneck (CPU cache, libc idiosynchrasy, etc.) am I hitting here?

#include <stdio.h>
#include <string.h>

#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);
}

Update: I'm running this on Ubuntu 12.04 64-bit, which has EGLIBC 2.15, on a Core i5-2520M.

Update: puts (s) has the same problem.

1 Answers
Related