title: C++ Input Performance
body: <p>I was trying to solve a problem on InterviewStreet. After some time I determine that I was actually spending the bulk of my time reading the input. This particular question had a lot of input, so that makes some amount of sense. What doesn't make sense is why the varying methods of input had such different performances:</p>
  
  <p>Initially I had:</p>
  
  <pre><code>std::string command;
  std::cin &gt;&gt; command;
  </code></pre>
  
  <p>Replacing it made it noticeably faster:</p>
  
  <pre><code>char command[5];
  cin.ignore();
  cin.read(command, 5);
  </code></pre>
  
  <p>Rewriting everything to use scanf made it even faster</p>
  
  <pre><code>char command;
  scanf("get_%c", &amp;command);
  </code></pre>
  
  <p>All told I cut the time reading the input down  by about a 1/3.</p>
  
  <p>I'm wondering there is such a variation in performance between these different methods. Additionally, I'm wondering why using gprof didn't highlight the time I was spending in I/O, rather seeming to point the blame to my algorithm.</p>