title: Reading key-value pairs as fast as possible in C++ from file
body: <p>I have a file with roughly 2 million lines like this:</p>
  
  <pre><code>2s,3s,4s,5s,6s 100000
  2s,3s,4s,5s,8s 101
  2s,3s,4s,5s,9s 102
  </code></pre>
  
  <p>The first comma separated part indicates a poker result in Omaha, while the latter score is an example "value" of the cards. It is very important for me to read this file as fast as possible in C++, but I cannot seem to get it to be faster than a simple approach in Python (4.5 seconds) using the base library. </p>
  
  <p>Using the Qt framework (QHash and QString), I was able to read the file in 2.5 seconds in release mode. However, I do not want to have the Qt dependency. The goal is to allow quick simulations using those 2 million lines, i.e. <code>some_container["2s,3s,4s,5s,6s"]</code> to yield <code>100</code> (though if applying a translation function or any non-readable format will allow for faster reading that's okay as well).</p>
  
  <p>My current implementation is extremely slow (8 seconds!):</p>
  
  <pre><code>std::map&lt;std::string, int&gt; get_file_contents(const char *filename)
  {
      std::map&lt;std::string, int&gt; outcomes;
      std::ifstream infile(filename);
  
      std::string c;
      int d;
  
      while (infile.good())
      {
          infile &gt;&gt; c;
          infile &gt;&gt; d;
          //std::cout &lt;&lt; c &lt;&lt; d &lt;&lt; std::endl;
          outcomes[c] = d;
      }
      return outcomes;
  }
  </code></pre>
  
  <p><strong>What can I do to read this data into some kind of a key/value hash as fast as possible</strong>?</p>
  
  <p>Note: The first 16 characters are always going to be there (the cards), while the score can go up to around 1 million.</p>
  
  <p>Some further informations gathered from various comments:</p>
  
  <ul>
  <li>sample file: <a href="http://pastebin.com/rB1hFViM" rel="nofollow">http://pastebin.com/rB1hFViM</a></li>
  <li>ram restrictions: 750MB</li>
  <li>initialization time restriction: 5s</li>
  <li>computation time per hand restriction: 0.5s</li>
  </ul>